In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what the five software packages commonly used in Django development are, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.
Django is an advanced Python Web framework that can help developers create web applications quickly.
The best way to build a Django website:
It's always a little painful to build a new project or application. You can use the built-in Django
Startproject
However, if you are as picky about how to do things as we are. Cookiecutter solves this problem by providing you with a quick and easy way to build projects or application templates that are easy to reuse. A simple example: type
Pip install cookiecutter
And then run the following command on the command line:
$cookiecutter https://github.com/marcofucci/cookiecutter-simple-django
Next you need to answer a few simple questions, such as your project name, directory, author name, E-Mail, and a few other configuration questions. These can help you fill in the details related to the project. We use the original "foo" as our directory name. So cokkiecutter created a simple Django project under the subdirectory "foo".
If you wander through the "foo" project, you will see that the other settings you just selected have passed the template and are embedded in the file along with the required subdirectories. This "template" is just being implemented.
Cookiecutter
The only parameter entered during the command is defined in the Github repository URL. This sample project uses a Github remote repository as a template; however, you can also use local templates, which are useful when building non-reuse projects.
We think cookiecutter is a great Django package, but in fact it is extremely useful when faced with pure Python or even non-Python related requirements. You can put all files precisely in any location in a repeatable way, making cookiecutter an excellent tool for simplifying (DRY) workflow.
The best static resource server: Whitenoise
For many years, hosting the static resources of a website-- pictures, Javascript, CSS-- is a very painful thing. Django's built-in django.views.static.serve view, as described in the Django article, "is not reliable in a production environment, so it should only provide accessibility to the development environment." But using a "real" Web server, such as NGINX or using CDN to host media resources, can be difficult to configure.
Whitenoice solves this problem very succinctly. It can set up static servers in the production environment as easily as in the development environment, and is hardened and optimized for the production environment. Its setup method is extremely simple:
Make sure you are using Django's contrib.staticfiles application and make sure that you set the STATIC_ROOT variable correctly in the configuration file.
Enable Whitenoise in the wsgi.py file:
From django.core.wsgi import get_wsgi_applicationfrom whitenoise.django import DjangoWhiteNoiseapplication = get_wsgi_application () application = DjangoWhiteNoise (application) >
It's really that simple to configure it! For large applications, you may want to use a dedicated media server and / or a CDN, but for most small or medium-sized Django sites, Whitenoise is powerful enough.
For more information about Whitenoise, please check the documentation.
The best tool for developing REST API: Django REST Framework
REST API is rapidly becoming the standard function of modern Web applications. API simply uses JSON conversations instead of HTML, and of course you can just use Django to do this. You can make your own view, set the appropriate Content-Type, and then return JSON instead of the rendered HTML response. This is what most people did before the release of API frameworks like Django Rest Framework (hereinafter referred to as DRF).
If you are familiar with Django's view classes, you will feel that building REST API with DRF is similar to using them, but DRF is only designed for specific API usage scenarios. Normal API settings require only a little code, so instead of providing a sample code that excites you, we emphasize some DRF features that make your life more comfortable:
API, which can be previewed automatically, makes your development and manual testing easy. You can check out the sample code for DRF. You can view API responses, and you don't need to do anything to support POST/PUT/DELETE-type operations. It is easy to integrate various authentication methods, such as OAuth, Basic Auth, or API Tokens. Built-in request rate limit. When combined with django-rest-swagger, API documents can be generated almost automatically. Extensive third-party library ecology.
Of course, you can build API without relying on DRF, but we can't imagine why you don't use DRF. Even if you don't use all the features of DRF, using a mature view library to build your own API will make your API more consistent, complete, and speed up your development. If you haven't started using DRF yet, you should find some time to experience it.
The Best CMS:Wagtail based on Django
Wagtail is the most popular application in the current Django CMS (content management system) world, and there is a good reason for its popularity. Like most CMS, it is extremely flexible and allows you to define different types of pages and their content through a simple Django model. With it, you can build a basically operational content management system from scratch in a few hours instead of days. To take a small example, defining an employee page type for your company's employees can be as simple as the following:
From wagtail.wagtailcore.models import Pagefrom wagtail.wagtailcore.fields import RichTextFieldfrom wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanelfrom wagtail.wagtailimages.edit_handlers import ImageChooserPanelclass StaffPage (Page): name = models.CharField (max_length=100) hire_date = models.DateField () bio = models.RichTextField () email = models.EmailField () headshot = models.ForeignKey ('wagtailimages.Image', null=True, blank=True) content_panels = Page.content_panels + [FieldPanel (' name') FieldPanel ('hire_date'), FieldPanel (' email'), FieldPanel ('bio',classname= "full"), ImageChoosePanel (' headshot'),]
What really stands out about Wagtail, however, is its flexibility and its easy-to-use modern management page. You can control where different types of pages are accessible, add complex additional logic to the page, and naturally support standard adaptation / approval workflows. In most CMS systems, you will encounter difficulties at some point in your development. When using Wagtail, we find a breakthrough through unremitting efforts, which makes it easy for us to develop a simple and stable system that makes the program run exactly as we want. If you are interested, we have written a [in-depth understanding of Wagtail] [17].
Provide the best tool for logging in to social accounts: django-allauth
Django-allauth is a reusable Django application that addresses your registration and certification needs. Whether you need to build a local registration system or a social account registration system, django-allauth can help you do it.
This application supports a variety of authentication schemes, such as user names or e-mail. Once a user has successfully registered, it can also provide a variety of account authentication strategies ranging from no authentication to email authentication. It also supports a variety of social and email accounts. It also supports plug-in registration forms that allow users to answer additional questions when registering.
Django-allauth supports more than 20 authentication providers, including Facebook, Github, Google, and Twitter. If you find a social networking site that it does not support, it is likely to provide access to the site through a third-party plug-in. The project also supports custom backends and can support custom authentication, which is great for everyone who needs custom authentication.
Django-allauth is easy to configure and well documented. The project has passed a lot of tests, so you can trust that all its parts will work properly.
Thank you for reading this article carefully. I hope the article "what are the five software packages commonly used in Django development" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.