学习django最好的方法是什么?

时间:2021-11-15 22:59:51

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

我真的想构建一个web应用程序;一些简单的东西,比如口袋妖怪卡片的数据库?

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

我听说过《被解救的姜戈》的精彩故事。哪里是最好的起点?

9 个解决方案

#1


78  

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:

这是我在我的博客上发表的一篇文章,回答了几乎完全相同的问题。它包含了这里已经给出的许多答案,以及一些额外的建议,其中一些是我的个人观点,另一些可能与我不同。希望有人觉得它有用:

Build Something

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一个典型的“Hello world”是一个博客网站,我也建议从这个开始。Django框架试图让普通的任务变得非常简单和简单,一个简单的博客功能的网站就是一个典型的例子。一个流利的Djangonaut可以在不到一个小时的时间内通过使用所有可用的库来编写一个简单的博客网站,因此它是一个很好的起点,可以让你了解Django是如何做事情的。

The Django Book

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的所有部分集成到MVC模型中,并对Django的工作如此简单以至于其他框架变得毫无必要地令人厌烦感到惊讶。

The Django Tutorials and Documentation

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的基础知识,你就几乎不需要别的了。文档也很棒,你自己去看看吧。

Pick a Django Version

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版本,并坚持使用它。在撰写本文时,大多数人正在使用两个主要版本,Django 1.2和Django 1.3,以及开发版本(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 1.0和1.1。这很好,而且基本上不是问题,但是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.

一旦选择了一个版本,请确保始终阅读Django文档的正确版本。你会在右边的侧边栏和你所在页面的url中看到你可以改变你正在查看的版本。Django的documentaion非常优秀,远远超越了其他任何东西,作者特别注意声明该版本中哪些函数是新的,哪些函数在以后的版本中被弃用。只要确保您意识到这一点,就不会浪费大量的时间来尝试在您的版本中不可用的东西。

Know what DRY means, and practice it

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的核心原则之一。如果您发现自己在Django中复制粘贴任何内容,几乎肯定有更好的方法。大多数程序员都会从经验中知道为什么这样做是不好的,但是简而言之,如果您的代码中有什么需要更改,或者您在某个地方犯了错误,您只需要在一个地方更改它。这很有用,因为如果有不止一个地方需要更改,并且您忘记了那个实例,那么您将会在代码中引入错误和错误。

Stay away from Class-based views

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.

Django 1.3的一个新特性是一组基于类的泛型视图。如果你不知道这意味着什么,不要担心。绝大多数关于Django的教程和书籍都不会提及它,主要是因为它太新了。这是一种旨在减少在创建视图时的遗憾的特性,从而遵循枯燥的原则。虽然它在某种程度上确实做到了这一点,但它也引入了大量的黑魔法,并且需要经常在Django源代码中摸索,以查看发生了什么。对于初学者来说,这并不理想。此外,现在为基于类的视图提供的错误消息常常指向完全错误的方向。远离它们,而是在开始时使用功能视图,正如大多数教程会告诉您的那样。如果您对Django比较熟悉,并且发现函数视图令人沮丧,那么请查看基于类的泛型视图。

Don't start out hosting on Google App Engine

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.

尽管GAE是免费的,并且非常适合可伸缩的Django应用程序,但是它也对您的登录过程进行了大量的限制,并且相关的文档非常稀少。作为一个初学者,不要从这条路径开始,因为许多普通的Django文档将突然不适用,您将不知道要做什么。更确切地说,从一项服务开始,比如epio, gondor。io,或者其他的。Epio仍在测试中,但也有免费的托管选项(每月使用一定数量)。由两个Django核心开发人员开发的,我强烈建议使用它们——对于Ruby on Rails来说,它们可以与Heroku相媲美。Ep。io正在关闭,但是Heroku最近也增加了一个Python托管选项。

Use *, Ask questions

My final piece of advice is to make use of * 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 "*" 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社区帮助您。在过去的几年里,它被证明是我学习Django的黑暗面的最大的资源,除了物理阅读Django代码(您也应该这样做!)祝你好运,尽情享受吧!

#2


14  

Build your first Django web application by reading Django tutorial.

通过阅读Django教程构建您的第一个Django web应用程序。

#3


9  

Read through the Django book.

通读《姜戈》这本书。

#4


8  

Build something. Anything. Keep it relatively simple and short, but start building it and make sure you finish building it. The project you have in mind right there might be perfect.

构建一些东西。任何东西。保持它相对简单和简短,但是开始构建它并确保完成它。你心目中的项目可能是完美的。

Reading documentation and books is extremely helpful, of course, but like any programming the only way to really learn Django is to practice with it. Building something tangible is pretty much the only way to get that practice.

当然,阅读文档和书籍是非常有用的,但与任何编程一样,真正学习Django的唯一方法是使用它进行实践。建立一些有形的东西是获得这种实践的唯一途径。

#5


7  

If you don't know Python, start your learning with that. People tend to get very frustrated when they try to learn a framework without knowing at least something about its programming language.

如果你不了解Python,那就从它开始学习吧。当人们试图学习一个框架而不知道它的编程语言时,他们往往会感到非常沮丧。

#6


2  

After obtaining basic knowledge of Django/Python, start reading Django by Examples, great articles.

在获得对Django/Python的基本知识之后,可以通过示例、伟大的文章开始阅读Django。

#7


1  

Official Django Website is a great place for learning and for reference. There is an awesome tutorial which is very good for beginners. Simple Silly Django Tutorial is a silly and simple tutorial which I wrote.

Django官方网站是一个学习和参考的好地方。有一个很棒的教程,对初学者很好。简单的Django教程是我编写的一个简单而愚蠢的教程。

Try to work on as much as projects as possible. Make your own versions of popular websites like facebook, twitter, imgur etc. Like anything, Practice makes perfect!

尽可能多地参与项目。制作你自己的流行网站版本,比如facebook, twitter, imgur等等。

#8


0  

The following screencast/tutorial is a nice way to jump in and create a Wiki from scratch:

下面的screencast/教程是一个很好的方法,可以让你从头开始创建一个Wiki:

After that, you might work through the tutorials and documentation available at the excellent django documentation site.

在此之后,您可以在优秀的django文档站点上使用教程和文档。

#9


0  

You can try "Learn Django in 4 hours - a fast track tutorial"

您可以尝试“在4小时内学习Django -一个快速教程”

For a kickstart into Django, please see:

想要了解《被解救的姜戈》,请参见:

http://slash4.de/blog/learn-django-in-4-hours

http://slash4.de/blog/learn-django-in-4-hours

It is designed to get you started with Django as fast as possible (no installation routines, etc.). It shows all the most important parts of Django - of course it is not possible to cover all aspects of Django in 4 hours, but this is not the intention of this course.

它的设计目的是让您尽可能快地启动Django(没有安装例程等)。它展示了Django所有最重要的部分——当然不可能在4小时内涵盖Django的所有方面,但这不是本课程的目的。

#1


78  

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:

这是我在我的博客上发表的一篇文章,回答了几乎完全相同的问题。它包含了这里已经给出的许多答案,以及一些额外的建议,其中一些是我的个人观点,另一些可能与我不同。希望有人觉得它有用:

Build Something

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一个典型的“Hello world”是一个博客网站,我也建议从这个开始。Django框架试图让普通的任务变得非常简单和简单,一个简单的博客功能的网站就是一个典型的例子。一个流利的Djangonaut可以在不到一个小时的时间内通过使用所有可用的库来编写一个简单的博客网站,因此它是一个很好的起点,可以让你了解Django是如何做事情的。

The Django Book

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的所有部分集成到MVC模型中,并对Django的工作如此简单以至于其他框架变得毫无必要地令人厌烦感到惊讶。

The Django Tutorials and Documentation

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的基础知识,你就几乎不需要别的了。文档也很棒,你自己去看看吧。

Pick a Django Version

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版本,并坚持使用它。在撰写本文时,大多数人正在使用两个主要版本,Django 1.2和Django 1.3,以及开发版本(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 1.0和1.1。这很好,而且基本上不是问题,但是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.

一旦选择了一个版本,请确保始终阅读Django文档的正确版本。你会在右边的侧边栏和你所在页面的url中看到你可以改变你正在查看的版本。Django的documentaion非常优秀,远远超越了其他任何东西,作者特别注意声明该版本中哪些函数是新的,哪些函数在以后的版本中被弃用。只要确保您意识到这一点,就不会浪费大量的时间来尝试在您的版本中不可用的东西。

Know what DRY means, and practice it

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的核心原则之一。如果您发现自己在Django中复制粘贴任何内容,几乎肯定有更好的方法。大多数程序员都会从经验中知道为什么这样做是不好的,但是简而言之,如果您的代码中有什么需要更改,或者您在某个地方犯了错误,您只需要在一个地方更改它。这很有用,因为如果有不止一个地方需要更改,并且您忘记了那个实例,那么您将会在代码中引入错误和错误。

Stay away from Class-based views

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.

Django 1.3的一个新特性是一组基于类的泛型视图。如果你不知道这意味着什么,不要担心。绝大多数关于Django的教程和书籍都不会提及它,主要是因为它太新了。这是一种旨在减少在创建视图时的遗憾的特性,从而遵循枯燥的原则。虽然它在某种程度上确实做到了这一点,但它也引入了大量的黑魔法,并且需要经常在Django源代码中摸索,以查看发生了什么。对于初学者来说,这并不理想。此外,现在为基于类的视图提供的错误消息常常指向完全错误的方向。远离它们,而是在开始时使用功能视图,正如大多数教程会告诉您的那样。如果您对Django比较熟悉,并且发现函数视图令人沮丧,那么请查看基于类的泛型视图。

Don't start out hosting on Google App Engine

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.

尽管GAE是免费的,并且非常适合可伸缩的Django应用程序,但是它也对您的登录过程进行了大量的限制,并且相关的文档非常稀少。作为一个初学者,不要从这条路径开始,因为许多普通的Django文档将突然不适用,您将不知道要做什么。更确切地说,从一项服务开始,比如epio, gondor。io,或者其他的。Epio仍在测试中,但也有免费的托管选项(每月使用一定数量)。由两个Django核心开发人员开发的,我强烈建议使用它们——对于Ruby on Rails来说,它们可以与Heroku相媲美。Ep。io正在关闭,但是Heroku最近也增加了一个Python托管选项。

Use *, Ask questions

My final piece of advice is to make use of * 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 "*" 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社区帮助您。在过去的几年里,它被证明是我学习Django的黑暗面的最大的资源,除了物理阅读Django代码(您也应该这样做!)祝你好运,尽情享受吧!

#2


14  

Build your first Django web application by reading Django tutorial.

通过阅读Django教程构建您的第一个Django web应用程序。

#3


9  

Read through the Django book.

通读《姜戈》这本书。

#4


8  

Build something. Anything. Keep it relatively simple and short, but start building it and make sure you finish building it. The project you have in mind right there might be perfect.

构建一些东西。任何东西。保持它相对简单和简短,但是开始构建它并确保完成它。你心目中的项目可能是完美的。

Reading documentation and books is extremely helpful, of course, but like any programming the only way to really learn Django is to practice with it. Building something tangible is pretty much the only way to get that practice.

当然,阅读文档和书籍是非常有用的,但与任何编程一样,真正学习Django的唯一方法是使用它进行实践。建立一些有形的东西是获得这种实践的唯一途径。

#5


7  

If you don't know Python, start your learning with that. People tend to get very frustrated when they try to learn a framework without knowing at least something about its programming language.

如果你不了解Python,那就从它开始学习吧。当人们试图学习一个框架而不知道它的编程语言时,他们往往会感到非常沮丧。

#6


2  

After obtaining basic knowledge of Django/Python, start reading Django by Examples, great articles.

在获得对Django/Python的基本知识之后,可以通过示例、伟大的文章开始阅读Django。

#7


1  

Official Django Website is a great place for learning and for reference. There is an awesome tutorial which is very good for beginners. Simple Silly Django Tutorial is a silly and simple tutorial which I wrote.

Django官方网站是一个学习和参考的好地方。有一个很棒的教程,对初学者很好。简单的Django教程是我编写的一个简单而愚蠢的教程。

Try to work on as much as projects as possible. Make your own versions of popular websites like facebook, twitter, imgur etc. Like anything, Practice makes perfect!

尽可能多地参与项目。制作你自己的流行网站版本,比如facebook, twitter, imgur等等。

#8


0  

The following screencast/tutorial is a nice way to jump in and create a Wiki from scratch:

下面的screencast/教程是一个很好的方法,可以让你从头开始创建一个Wiki:

After that, you might work through the tutorials and documentation available at the excellent django documentation site.

在此之后,您可以在优秀的django文档站点上使用教程和文档。

#9


0  

You can try "Learn Django in 4 hours - a fast track tutorial"

您可以尝试“在4小时内学习Django -一个快速教程”

For a kickstart into Django, please see:

想要了解《被解救的姜戈》,请参见:

http://slash4.de/blog/learn-django-in-4-hours

http://slash4.de/blog/learn-django-in-4-hours

It is designed to get you started with Django as fast as possible (no installation routines, etc.). It shows all the most important parts of Django - of course it is not possible to cover all aspects of Django in 4 hours, but this is not the intention of this course.

它的设计目的是让您尽可能快地启动Django(没有安装例程等)。它展示了Django所有最重要的部分——当然不可能在4小时内涵盖Django的所有方面,但这不是本课程的目的。