Learning and building Django framework
Preface
There are two versions of the compiler pycharm: community version and professional version
For the professional version, Django can be created directly in the create project in the upper left corner of the file
For the community version, Django is not in the create project, we can create Django through the terminal
Prerequisite: Environment configuration
python3.7 (with Python environment)
Django 3.1.3 (with Django environment) has been installed in the settings
The terminal builds the basic framework of Django
-Build a Django project
-Enter the terminal
In the specified document, open the powershell window
-Create a Django project
Here is a demonstration with powershell
(you can also enter the preset folder in the pycharm terminal) to
execute the project creation command
django-amdin startproject mySite
At this point, a mySite folder is generated under the django directory
-View project structure
Continue to view the frame structure in the terminal
tree /f mySite
The frame form is
mySite/
│ manage.py
│
└─mySite
asgi.py
settings.py
urls.py
wsgi.py
__init__.py
-Build Django functional area
Enter the mySite project and create a functional area
cd mySite
django-admin startapp myApp
At this point, the created myApp appears in mySite
-View the overall structure
cd..
tree /f mySite
At this point, the basic structure of Django is in sight
mySite/
│ manage.py
│
├─myApp
│ │ admin.py
│ │ apps.py
│ │ models.py
│ │ tests.py
│ │ views.py
│ │ __init__.py
│ │
│ └─migrations
│ __init__.py
│
└─mySite
asgi.py
settings.py
urls.py
wsgi.py
__init__.py
-Configuration file parameters
--Settings file configuration
Open the pycharm compiler and add the myApp file address in the settings in mySite
--Urls file configuration
Add index interface
from myApp import views
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index),
]
--Views file configuration
Feel free to design a paragraph. For example: hi, this is a funny stuff!
from django.http import HttpResponse
def index(request):
return HttpResponse('hi, this is a funny stuff!')
Enter mySite in the terminal and run manage
cd mySite
python manage.py runserver
Show address after carriage return
Enter the display result through the browser
Enter http://127.0.0.1:8000/ in the browser
At this point, the terminal displays 200 and the access is successful.
Finally, if you want to end the operation, you can exit in the terminal through Ctrl+Break~
Write at the end
If my article is helpful to you, please like and follow!
If you are confused about my article, please leave a message!
Down to earth, there will be a bright future!