Python 开始学习 Django 的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4048973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 14:01:45  来源:igfitidea点击:

What's the best way to start learning django?

pythondjango

提问by SRUCLA

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?

我听说过关于 Django 的好消息。最好的起点是哪里?

采纳答案by Herman Schaaf

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 Book。作者有一段时间没有研究它或保持最新状态(由于其年轻的性质,Django 变化非常频繁),但它可以在线免费获得并强烈推荐。阅读关于如何设置系统、Django 的所有部分如何组合到 MVC 模型中的前几章,你会惊讶于 Django 是如何做事如此简单以至于其他框架变得毫无意义的令人厌烦的。

The Django Tutorials and Documentation

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 的基础知识,您几乎不需要其他任何东西。文档也很棒,自己去看看。

Pick a Django Version

选择一个 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 版本并坚持使用是个好主意。在撰写本文时,大多数人使用两个主要版本,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 已经存在了大约四五年了,你会发现很多分散在 Google 上的教程都是针对 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 的文档确实非常出色,远远超出了其他任何东西,作者非常小心地特别说明了该版本中哪些是新的,哪些在以后的版本中已被弃用。只要确保您意识到这一点,就不会浪费无数小时试图使您的版本中不可用的东西工作。

Know what DRY means, and practice it

知道 DRY 是什么意思,并实践它

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.

DRY:“不要重复自己”是 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 的教程和书籍都没有提及它,主要是因为它太新了。这是一个功能,旨在减少创建视图的重复,从而遵循 DRY 原则。虽然它在某种程度上确实做到了这一点,但它也引入了很多黑魔法,并且需要经常在 Django 源代码中四处寻找以查看发生了什么。对于初学者来说,这不太理想。此外,现在为基于类的视图提供的错误消息通常会指向完全错误的方向。远离它们,而是在开始时使用功能视图,正如大多数教程会告诉您的那样。当你'

Don't start out hosting on Google App Engine

不要开始在 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 Herokualso recently added a Python hosting option.

虽然 GAE 是免费的并且非常适合可扩展的 Django 应用程序,但它也对您的登录过程引入了很多限制,而且相关文档极其稀缺。作为初学者,不要从那条路线开始,因为很多正常的 Django 文档会突然不适用,你将不知道该怎么做。相反,从像epigondor.io许多其他服务这样的服务开始。Epio 仍处于测试阶段,但也有免费托管选项(每月最多使用一定数量)。由两个 Django 核心开发人员开发,我强烈建议使用它们 - 它可与 Heroku for Ruby on Rails 相媲美。Ep.io 即将倒闭,但Heroku最近还添加了Python 托管选项.

Use StackOverflow, Ask questions

使用 StackOverflow,提问

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!

我的最后一条建议是在遇到问题时随时使用 StackOverflow。首先,他们几乎可以回答您梦寐以求的任何问题。如果您在网站上找不到它,找到问题答案的一个好方法是将“stackoverflow”作为 google 搜索词的一部分附加。否则,发布一个问题,让 Django 社区帮助你。在过去的几年里,它被证明是我学习 Django 阴暗面的最大资源,除了亲自阅读 Django 代码(你也应该这样做!)。祝你好运,享受!

回答by Garrett Hyde

Read through the Django book.

通读Django 书

回答by ShZ

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 的唯一方法就是练习它。建立有形的东西几乎是获得这种实践的唯一途径。

回答by Ivan Teoh

Build your first Django web application by reading Django tutorial.

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

回答by ars

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

以下截屏视频/教程是从头开始并创建 Wiki 的好方法:

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

之后,您可以浏览优秀django 文档站点上提供的教程和文档。

回答by darioo

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,请从它开始学习。当人们尝试学习一个框架而不至少了解其编程语言时,往往会感到非常沮丧。

回答by Adil

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

获得 Django/Python 的基础知识后,开始阅读Django by Examples,很棒的文章。

回答by omoser

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

你可以试试“ 4小时学好Django——快速入门教程

For a kickstart into Django, please see:

有关 Django 的快速入门,请参阅:

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 的所有方面,但这不是本课程的意图。