In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "the environment and project building of Python framework Django". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Characteristics
Let's first take a look at the features of the Django framework:
Powerful database capabilities: with Python class inheritance, a few lines of code can have a dynamic database operation API and execute SQL statements if necessary.
Built-in powerful background function: a few lines of code let the site have a strong background, easy to manage content.
Elegant URL: use the regular matching URL and pass it to the corresponding function.
Template system: powerful, easy to expand template system, easy to design, code and style separate design, easier to manage.
Caching system: better performance and faster loading when combined with memcached or other caching systems.
Internationalization: full support for multilingual applications, allowing you to define translated characters and easily translate into different languages.
Django installation
You can easily install Django with the pip command. If you have Python 3.x and Python 2.x installed on your computer, remember to add a version distinction before the command. For example, if I want to install it into my Python 3 environment, refer to the following command.
Python3-m pip install Django
Environment variable setting
Find the django-admin.exe file in the subdirectory Scripts under Python's installation directory and add the directory of this file to the environment variable path. For example, my configuration path is:
E:\ py3\ Scripts
Verify the installation
Enter the Python interactive environment and enter the following two lines of commands to display the current version of Django, indicating that the installation is successful.
> import django
> > django.get_version ()
'2.1.1'
Create a project
You can create a Django project in any of the following ways.
1. Enter the following command in the cmd command to create.
Django-admin startproject mysite
2, use the powerful editor Pycharm to create, create a new django project, set the relevant parameters can be created.
3. Partners who use the community version (free version) of Pycharm will find that there is no Django option on the left when creating the project, how to create it? Using the first method, we create the Django project with the command in cmd, and then open the existing project in Pycharm.
The directory structure after the creation of the Django project is as follows.
Catalog description:
Mysite: the container for the project.
Manage.py: a practical command line tool that allows you to interact with the Django project in a variety of ways.
Mysite/init.py: an empty file that tells Python that the directory is a Python package.
Mysite/settings.py: the setup / configuration of the Django project.
Mysite/urls.py: the URL statement of the Django project; a website "directory" driven by Django.
Mysite/wsgi.py: a portal to a WSGI-compatible Web server to run your project.
Create APP
Under the Django project, multiple small modules can be created, each of which is independent of each other and can share Django project resources. Enter the following command in the Terminal terminal window below Pycharm to create a small module named "contention".
After creation, files related to the "competition" module will be added to the project.
Link configuration
Add the route jump of url in mysite/urls.py, import the views in the competition module, and increase the index link jump.
View function configuration
Configure the business processing logic in the views.py file of the "contention" module, here we simply output the string "Hello contention", import the HttpResponse module, create a new index function, and output the string that needs to be output by HttpResponse, so that the output can be identified by the HTTP protocol.
In this way, we point the url of index to the index () view function in views, which receives user requests and returns a string of "Hello contention".
Start the service
First configure the jump address in Pycharm, click the Django project name in the right menu bar, and click Edit Configuration to enter the environment configuration page.
Enter the url and port to be configured and save it.
When you run the Django project mysite after configuration, you will actively open the browser and find that the page reports an error of 404. the error message in the next page is analyzed and the jump link is incorrect.
According to the supported links, we add index after the link so that we can access it successfully.
This is the end of the introduction of "the Environment and Project Building of Python Framework Django". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.