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

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

问题描述

我真的想要构建一个Web应用程序;一些简单的例子,也许是一个神奇宝贝卡的数据库?



我听说过Django的好东西。哪里会是最好的地方开始?

解决方案

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



构建东西



我可以给出的最好的建议是开始构建一些东西。 Django的一个典型的Hello world是一个博客网站,我也建议从此开始。 Django框架尝试使常见任务变得非常简单和简单,而具有简单博客功能的网站就是一个典型的例子。流畅的Djangonaut可以通过使用所有可用的图书馆在不到一个小时的时间内编写一个简单的博客网站,因此它是开始Django做某事的好地方。



Django Book



当然,在您可以跳入并开始编码之前,您需要使用Django让系统启动并运行,并学习基础。一个很好的资源是 Django Book 。作者在一段时间内还没有完成任务,或者保持原状(由于年轻的性质,Django的变化非常的频繁),但它是免费的在网上提供,强烈推荐。阅读关于如何设置系统的前几章,Django的所有部分如何融合到MVC模型中,并感到惊讶的是Django如何做到这一点,使得其他框架变得非常复杂。



Django教程和文档



Django网站,一旦你有Django的基础知识,你几乎不需要任何其他的东西。



选择Django版本



对于初学者选择一个Django版本是一个好主意,并坚持下去。在撰写本文时,大多数使用了Django 1.2和Django 1.3两个主要版本,以及开发版本(Django开发人员的版本和测试版本,作为主要版本发布之前) )。开始时不要使用开发版本 - 你一定会遇到麻烦。



最重要的是Django已经存在大约四个五年过去了,您将会发现分散在Google上的大部分教程将针对Django 1.0和1.1。没关系,大多没有问题,但Django自那以来添加了相当多的功能,因此大部分教程和代码段已经过时了。尝试在可能的情况下坚持针对您的版本的教程。



选择版本后,请确保始终阅读正确版本的 Django文档。您将在右侧侧栏和您所在页面的网址中看到,您可以更改您正在查看的版本。 Django的文档是真正优秀的,远远超出了其他任何东西,作者非常小心,特别指出哪个功能是新版本的功能,哪些功能在以后的版本中被弃用。只要确保你知道这一点,所以你不要浪费无数小时,试图让你的版本中不可用的工作。



知道什么DRY意味着,并练习它



DRY:不要重复自己是Django背后的核心原则之一。如果您发现自己在Django中复制任何东西,几乎肯定会有更好的方法。大多数程序员会从经验中知道为什么这样的复制是坏的,但总之,如果您的代码中的某些内容需要稍后更改,或者如果您在某处发生错误,则只需要在一个地方更改。这很有用,因为如果有不止一个地方需要改变,而你忘记了这个例子,那么你会在你的代码中引入错误和错误。



远离从基于类的视图



Django 1.3的新增功能是一个基于类的通用视图的整个数组。如果你不知道这是什么意思,别担心。绝大多数关于Django的教程和书籍都不会提及,主要是因为它是新的。这是一个功能,旨在减少创建视图的复制,从而遵循DRY原则。虽然它在某种程度上做到了这一点,但它也引入了很多黑魔法,并且需要经常在Django源代码中去查看发生了什么。对于初学者来说,这不太理想。此外,错误消息现在提供给基于类的视图通常会指向完全错误的方向。远离他们,而是开始使用功能视图,因为大多数教程将告诉你。当您对Django有更多的用处,您会发现功能视图的复制令人沮丧,请查看基于类的通用视图。



不要开始托管Google App Engine



虽然GAE对于可伸缩的Django应用来说是免费的,但它也为您的登录过程引入了很多限制,而且文档非常少。作为一个初学者,不要以这种方式开始,因为很多正常的Django文档将突然不适用,你不会知道该怎么做。相反,请从 epio gondor.io 许多其他。 Epio还处于测试阶段,但也有一个免费的托管选项(达到一定的月度使用量)。由两个Django核心开发人员开发,我强烈建议使用它们 - 它与Ruby on Rails的Heroku相当。 Ep.io正在关闭,但 Heroku 也最近添加了一个 Python托管选项



使用StackOverflow,提问



我的最后一条建议是随时随地使用StackOverflow。首先,他们已经有了你可以想到的任何问题的答案。如果您在网站上找不到,找到问题答案的好方法是将stackoverflow作为Google搜索字词的一部分。否则,发布一个问题,让Django社区帮助你。除了身体阅读Django代码(你也应该这样做)之外,在过去几年里,我已经被证明是我学习Django黑暗层面的最好的资源。祝你好运,享受!


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

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:

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.

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.

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.

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.

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.

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.

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.

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.

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.

Use StackOverflow, Ask questions

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天全站免登陆