Environment setup
Before installing Django, you need to install the python environment and pycharm.
Currently, Django 1.6.x and above are fully compatible with Python 3.x.
Python installation tutorial: https://blog.csdn.net/David_house/article/details/100110542
Project creation
- Open pycharm, select File–>New Project
- Create a Django project.
Make sure your computer is connected to the Internet. Pycharm will automatically download and install Django when creating a Django project (you don’t need to install Django in advance, which is very convenient. If you can’t find the Django option, it may be that the pycharm version is older).
Create After completion, the following project list will appear:
Here is a brief explanation of the role of each file:
- __init__.py: An empty file that tells Python that the directory is a Python package.
- asgi.py: A portal to an ASGI-compatible web server to run your project.
- settings.py: Settings/configuration for this Django project.
- urls.py: The URL declaration of the Django project; writes the request path.
- wsgi.py: A portal to a WSGI-compatible web server to run your project.
- manage.py: A useful command line tool that allows you to interact with this Django project in various ways.
application creation
- Enter the above project directory and execute the following command:
python manage.py startapp app
An app folder will be generated:
the role of the main file:
- models.py: data model file
- views.py: Add processing or query code