Preface: With the release of the second candidate version of Django 1.4, although Python 3 is not supported yet, the Django team is already working on the plan. According to the official blog, Django 1.5 will experimentally support Python 3.
As an outstanding Python open source framework, Django may not be able to obtain other popular frameworks such asRailsThere are so many praises, but it is as refined as other frameworks, paying great attention to the DRY (Don't Repeat Yoursef) principle and component reusability, and making encoding simpler through automated processes.
If you can use certain methods and techniques flexibly in a Django project, it will greatly speed up software development while avoiding many headaches. The author lists a few points below. These methods can help programmers of any level more proficient in using Django.
0. Use relative paths in configuration
Some reasons make projects likely to be migrated back and forth often. This is definitely a difficult problem without planning this possibility in advance. Rob Hudson has an excellent skill to ensure that your Django project can be easily moved back and forth during deployment. Just write a few lines of code in your configuration file().
import os BASE_DIR = ((__file__)) TEMPLATE_DIRS = ( BASE_DIR + '/templates', )
1. Use the {%url%} tag
Use backward compatible {%url%} tags to replace hard-coded hrefs whenever possible, achieving the same effect as using urls with absolute paths (of course not to do this). Moving your Django project will not affect those links. (Translator's note: For example, if we have a function pointing to the about page r'^about/$', you can {% url as about_url %} and use the variable {{about_url}} to replace the absolute URL address) Although it is not the most advanced trick yet, it is indeed worth applying to your Django project.
2. Try to apply Django admin to PHP project
One of the greatest features of Django is the user verification system that has become the core feature of Django. It is easy to install and is mainly used for user authentication and some other necessary configurations. This cool user system is even recommended to apply to your PHP project.hereThere is a good solution for Jeff Croft on why Django can serve as a system management module in any language or any application.
3. Use an independent media server
It is not a big problem to place static files in the same server as the Django project in the development environment, but it should not be used in the production environment. Why? Efficiency issues. Given a reasonableexplain. The performance will be effectively improved through an independent server to handle static files. If you don’t want to buy a server, it is relatively cheaper to use Amazon S3.
4. Use the Debugger toolbar
Debugging tools are indispensable for any language. They are able to speed up development and point out potential flaws. Rob Hudson has developed a very useful django for developersDebugging Tools。
5. Use Django unit test
useUnit TestingMake sure your code changes are the same as expected without breaking any old code for backward compatibility. One powerful feature of Django is that it can write unit tests extremely simply. Django can also use python directlyText TestandUnit Testing. Django's documentation provides a detailed tutorial and sample code on how to do unit tests to make the code run correctly and remove nasty bugs
6. Use quick check card
hereThere are two pages of quick check cards, and what you might have to search for for a long time in the Django documentation is clear at a glance here. It contains the following topics
template:
Template tags and options
Template filters and options
Quick review of date formatting syntax
Model:
Domain and options
Optional options for common domains
Meta-type Optional
Model management options
Form:
Domain and Optional
Commonly used domain options
Standard Error Message Key Value
7. Use Django-chunks
Besides it's easier to create blocks using Django's rich text editor,Django-chunksAlso used in templates, this is an indispensable tool for reusing code blocks.
8. Use Memcache
If performance has become a tough problem in your Django project, then you will need to use some caching strategies. However, Django provides many options for cache. The best thing at the moment is undoubtedly Memcache. It is very simple to install memcache with Django, if you use cmemcache module. As long as the module is installed, you only modify one line of configuration items, your Django page becomes brisk.
9. Using Django, it’s better to act than to move
If you still don't fully understand the power of Django after you read this article, one reasonable reason to use Django in your next project is that it can save time in various software designs. Jeff Croft explains whyCreate a project with Django more efficiently than you design it yourself. Django allows you to extend your own web site without worrying about design or code and database compatibility, it will work great.