In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Environment: in order to enable the server to develop multiple applications, the environment version does not affect each other, using virtualenv to create an independent and isolated environment for development and use.
# install virtualenv:
[root@vps django] # pip3 install virtualenv
# create a virtual environment
[root@vps django] # virtualenv django_env
Using base prefix'/ usr/local'
New python executable in/ django/django_env/bin/python3.5
Also creating executable in/ django/django_env/bin/python
Installing setuptools, pip, wheel...done.
# using a virtual environment
[root@vps django] # source django_env/bin/activate
# install django in a virtual environment
(django_env) [root@vps django] # pip3 install django==1.10
Terminology:
The role of project is to provide configuration files, such as where to define database connection information, list of installed app, TEMPLATE_DIRS, and so on.
An app is a collection of Django functions, usually including models and views, that exist as a package structure of the Python.
For example, Django itself has some app built into it, such as an annotation system and an automatic management interface. One of the key points of app is that they are easily portable to other project and reused by multiple project.
# 1. Create a project project
(django_env) [root@vps django] # django-admin startproject my_project
After you create a project, several files are generated
# 2. You can create an application app in either of the following two ways
(django_env) [root@vps my_project] # django-admin startapp first_app
(django_env) [root@vps my_project] # python3 manage.py startapp second_app
# 3. Connect to the database and use pymsql to connect to MySQLdb in Python3, otherwise you will encounter the following pit
Solution:
1)。 Install pymysql wheels:
(django_env) [root@vps my_project] # pip3 install pymysql
2)。 After the execution is successful, open _ _ init__.py and add the following:
3)。 Modify settings.py:
4)。 Synchronize the database:
This method can create tables, and when you add a class to models.py, run it to automatically create tables in the database instead of manually.
(django_env) [root@vps my_project] # python3 manage.py migrate
After the database synchronization is successful, some tables are generated in the connected library.
# 4. Use your own development server, which can only be debugged during development. Online use is not recommended.
(django_env) [root@vps my_project] # python3 manage.py runserver 0.0.0.0 purl 8000
Performing system checks...
System check identified no issues (0 silenced).
January 04, 2017-02:24:16
Django version 1.10, using settings' my_project.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[04/Jan/2017 02:25:15] "GET / HTTP/1.1" 200 1767
Not Found: / favicon.ico
# create a login account password at the backend
(django_env) [root@vps my_project] # python3 manage.py createsuperuser
Username (leave blank to use 'root'): admin
Email address: admin@admin.com
Password:
Password (again):
The true face of Lushan Mountain
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.