I. "Using django2.0 to develop" environment deployment and initialization projects
Discover that there is nothing better than the Django series tutorial, so I'm going to write a set of tutorials to teach you how to use django2.0
The entire tutorial is done around a project that focuses on the entire environment and the projects under initialization, as well as some common operations in development
Project Address: Https://gitee.com/ccnv07/django_example
Project Introduction
Probably is to use Python to develop a CMS system, and you know dede,phpcms some similar, you can register, login, have membership system, publish articles, front desk browsing articles, backstage management and other functions.
Environment for development use
The Python version used is 3.6.5, many installation tutorials on the web
The virtual environment uses pipenv, which can be installed with PIP
The Django version is 2.0.
Database using mysql5.6
Installing Django
After you create the virtual environment, execute the following installation command
pipenv install django==2.0
# 查看django的版本python -m django --version> 2.0
Create our Project
django-admin startproject cms
Then found a more CMS directory, it long below this
Connecting to a database
Using the Python.pymysql module
So let's install it first.
pipenv install pymysql
Modify the configuration in the cms/settings.py
# cms/settings.pyDATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘NAME‘: ‘cms‘, ‘USER‘: ‘root‘, ‘PASSWORD‘: ‘123123‘, ‘HOST‘: ‘127.0.0.1‘, ‘PORT‘: 3306, ‘OPTIONS‘: { ‘autocommit‘: True } }}
Because Django supports MYSQLDB by default, you need to add the following code to make Pymysql the MYSQLDB
# cms/__init__.pyimport pymysqlpymysql.install_as_MySQLdb()
Run a simple server in the development process
cd cms/python manage.py runserver
will prompt the following
is to tell you to start running a development server on 127.0.0.1:8000, exit please press CTRL + C
You can also specify your own port and IP
python manage.py 0.0.0.0:5000
This server can only be used for development and testing and cannot be used to deploy production environments. This command will be used frequently in the subsequent development process, so please keep in mind.
I. "Using django2.0 to develop" environment deployment and initialization projects