开始学习Django的最佳方法是什么? [英] What's the best way to start learning django?

查看:65
本文介绍了开始学习Django的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想构建一个Web应用程序;一些简单的事情,例如一个神奇宝贝卡的数据库?

I really want to build a web application; something simple, maybe a database of Pokémon cards for instance?

我听说过有关Django的精彩文章。哪里是最好的起点?

I've heard excellent things about Django. Where would be the best place to start?

推荐答案

这是我在博客上发的帖子,几乎回答了完全相同的问题。它包含此处已经给出的许多答案,以及一些额外的建议,其中一些是我的个人观点,其他可能与我有所不同。希望有人会发现它有用:

This is from a post I made on my blog, answering almost exactly same question. It contains many of the answers already given here, as well as some extra advice, and some of it is my personal opinion, and others may differ from me. Hopefully someone finds it useful:

我能提供的最佳建议是从构建东西开始。 Django的典型 Hello world是一个博客网站,我也建议从此开始。 Django框架试图使普通任务变得非常容易和简单,并且具有简单博客功能的网站就是一个典型示例。精通Djangonaut的人可以使用所有可用的库在不到一个小时的时间内编写一个简单的博客网站,因此,它是一个很好的起点,可以让您了解Django的工作方式。

The best advice I can give is to start by building something. A typical "Hello world" for Django is a blog website, and I would also recommend starting with that. The Django framework tries to make common tasks extremely easy and simple, and a website with simple blogging functionality is a typical example. A fluent Djangonaut can code up a simple blog website in less than an hour by using all the libraries available, and therefore it's a good place to start and get a feel for how Django does things.

当然,在您可以跳入并开始编码之前,您需要启动系统并在Django上运行,并学习基础。为此的一个很好的资源是 Django Book 。作者们已经有一段时间没有研究它了,或者一直保持最新(由于它的年轻特性,Django经常更改),但是它可以在线免费获得,强烈推荐。阅读前几章,内容涉及如何设置系统,Django的所有部分如何配合到MVC模型中,以及Django的工作方式如此简单,以至于其他框架变得非常繁琐,令人惊讶。

Of course, before you can just jump in and start coding, you need to get your system up and running with Django, and learn the basics. A great resource for that is the Django Book. The authors haven't worked on it in a while or kept it quite up to date (due to its young nature, Django changes quite frequently), but It's freely available online and highly recommended. Read the first few chapters on how to set up your system, how all the parts of Django fit together into the MVC model, and be amazed by how Django does things so simply that other frameworks made unnecisarily tiresome.

Django网站,一旦掌握了Django的基础知识,您几乎不需要其他任何东西。该文档也很棒,请自己看看。

There are so many great tutorials on the Django website, that you'll almost need nothing else once you have the basics of Django down. The documentation is also fantastic, go take a look for yourself.

对于初学者,最好选择一个Django版本并坚持使用。在撰写本文时,大多数人都使用两个主要版本,即Django 1.2和Django 1.3,以及开发版本(Django开发人员使用的版本,并在将其发布为主要版本之前测试其更改) )。刚开始时不要使用开发版本,否则肯定会遇到麻烦。

For a beginner, it will be a good idea to pick a Django version, and stick with it. At the time of this writing, there are two main versions being used by most, Django 1.2 and Django 1.3, as well as the development version (the version that the Django developers work on and test changes in before it gets released as a major version). Don't use the development version when you're starting out - you're bound to run into trouble.

最大的问题是Django已经存在了大约四个或六个月。五年过去了,您会发现散布在Google上的许多教程都针对Django 1.0和1.1。很好,而且基本上不是问题,但是Django从那时起增加了很多功能,因此大部分教程和代码段都已过时。尽可能坚持使用针对您的版本的教程。

The big thing is that Django has existed for around four or five years now, and much of the tutorials you'll find scattered over Google will be aimed at Django 1.0 and 1.1. That's fine, and mostly not a problem, but Django's added quite a lot of functionality since then that makes most of those tutorials and code snippets obsolete. Try to stick to tutorials that are aimed at your version, where possible.

一旦选择了一个版本,请确保始终阅读正确的 Django文档。您会在右侧的侧边栏中以及页面的网址中看到,可以更改要查看的版本。 Django的文档确实非常出色,而且远远超出了其他任何文档,并且作者非常小心地指出了该版本中的哪些新功能以及在以后的版本中不推荐使用的功能。只需确保您意识到这一点,就可以避免浪费大量的时间来尝试进行版本中不可用的工作。

Once you've picked a version, make sure you always read the correct version of the Django documentation. You'll see on the right-hand side sidebar and in the url of the page you are on that you can change the version you're looking at. Django's documentaion is truly excellent and far beyond anything else out there, and the authors take great care to specifically state which functions are new to that version, and which are deprecated in later versions. Just make sure you're aware of that, so that you don't waste countless hours trying to make something work that's not available in your version.

DRY:不要重复自己是Django背后的核心原则之一。如果您发现自己在Django中复制粘贴了任何内容,几乎可以肯定有一种更好的方法。大多数程序员将从经验中知道为什么这样的重排是不好的,但是总之,如果以后需要更改代码中的某些内容,或者您​​在某个地方犯了错误,则只需要在一个位置进行更改即可。这很有用,因为如果有多个地方需要更改,而您忘记了该实例,则会在代码中引入错误和错误。

DRY: "Don't Repeat Yourself" is one of the core principles behind Django. If you find yourself copy-pasting anything in Django, there's almost certainly a better way to do it. Most programmers will know from experience why repitition like that is bad, but in short, if something in your code needs to change later on or if you made a mistake somewhere, you only need to change it in one place. That's useful, because if there is more than one place needing change, and you forget about that instance, you'll be introducing errors and bugs into your code.

Django 1.3的一个新功能是提供了一系列基于类的泛型视图。如果您不知道这意味着什么,请不用担心。关于Django的绝大多数教程和书籍都没有提及它,主要是因为它太新了。此功能旨在减少创建视图时的麻烦,从而遵循DRY原理。尽管这样做确实在一定程度上做到了,但是它还引入了很多黑魔法,并且需要经常在Django源代码中反复研究以了解发生了什么。对于初学者来说,这并不理想。另外,现在为基于类的视图提供的错误消息通常将您引向完全错误的方向。远离它们,而是开始使用功能视图,因为大多数教程都会告诉您。如果您对Django习以为常,并且发现功能视图的麻烦令人沮丧,请查看基于类的泛型视图。

A new addition to Django 1.3 is a whole array of Class-based Generic Views. If you don't know what that means, don't worry. The vast majority of tutorials and books about Django won't make any mention of it, mainly because it is so new. It's a feature that is meant to lessen the repitition in creating views, thereby following the DRY principle. While it does do that to some extent, it also introduces a lot of black magic and the need to frequently go scratch around in the Django source code to see what's going on. For the beginner, that is less than ideal. In addition, the error messages as they are now provided for Class-based views often point you in the completely wrong direction. Stay away from them, and rather use functional views in the beginning, as most tutorials will tell you to. When you're a bit more used to Django and you find the repitition of functional views frustrating, look into Class-based Generic Views.

虽然GAE是免费的,并且非常适合可扩展的Django应用程序,但它也对您的登录过程带来了很多限制,并且有关该文档的资料非常匮乏。作为初学者,不要以这种方式开始,因为许多常规的Django文档突然将不适用,并且您也不知道该怎么做。而是从类似 epio gondor.io 很多其他人 Epio仍处于测试阶段,但也有免费的托管选项(每月一定量的使用量)。我强烈建议使用两个Django核心开发人员开发的程序,它与Ruby on Rails的Heroku相当。 Ep.io即将关闭,但 Heroku 最近还添加了 Python托管选项

While GAE is free and great for scalable Django apps, it also introduces a lot of restrictions on your login process, and the documentation on that is extremely scarce. As a beginner, don't start out with that route, since lots of the normal Django documentation will suddenly not apply, and you won't know what to do. Rather, start with a service like epio, gondor.io, or many others . Epio's still in beta, but have a free hosting option as well (up to a certain amount of monthly usage). Developed by two of the Django core developers, I strongly recommend using them - it's comparable to Heroku for Ruby on Rails. Ep.io is closing down, but Heroku also recently added a Python hosting option.

最后一条建议是每当您遇到困难时,都可以使用StackOverflow。首先,他们已经对几乎所有您梦dream以求的问题都有答案。如果您在网站上找不到它,那么找到问题答案的一个好方法是在您的Google搜索字词中添加 stackoverflow。否则,发布一个问题,让Django社区帮助您。在过去的几年中,除了实际阅读Django代码(您也应该这样做)之外,它被证明是我学习Django较黑暗面的最大资源。祝你好运,并享受!

My final piece of advice is to make use of StackOverflow any time you get stuck. First off, they already have the answer to just about any question you can dream of. If you can't find it on the site, a good way to find the answer to your question is to append "stackoverflow" as part of your google search terms. Otherwise, post a question and let the Django community help you out. It's proven to be my greatest resource in learning the darker sides of Django over the last few years, apart from physically reading the Django code (which you should also do!). Good luck, and enjoy!

这篇关于开始学习Django的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆