Vue and Django front and back end separation practice (registration function)
編輯:Python
1. Vue and Django Front and back end separation practice ( Registration function )
Registration page
application layer
Control layer
The data layer ( Users add )
database ( Add to database )
2. Register the list to get database data
Background interface ( Get the list of users )
Front end display
3. problem
3.1 https;http Agreement question ,
Install the module django-sslserver
pip install django-sslserver
stay setting.py Add two configurations to the file
Use caution SECURE_SSL_REDIRECT
When SECURE_SSL_REDIRECT = False when ,http No response to the request ,https Request to access correctly .
When SECURE_SSL_REDIRECT = True when ,http Request will be repeated directional https, here django Support https, Can be accessed correctly .
Generate certificate command
python manage.py runsslserver
This message appears after running the command
Using SSL certificate: /Users/xx/Desktop/Django-test/venv/lib/python3.10/site-packages/sslserver/certs/development.crt Using SSL key: /Users/xx/Desktop/Django-test/venv/lib/python3.10/site-packages/sslserver/certs/development.key
–cert Specify the certificate to use –key Specify the key to use
The current method is to comment out crsf Part of the configuration
3.3 Django Get the database The content of The type of question
Background and purpose
I wanted to use Django Pull from the database All data of the user list , And back to the front end
Use Django obtain mysql Data time , It looks like this
We need to pay attention to reg Variable data type problem ,Django obtain mysql And then back to QuerySet type , It may need to be converted to json Format or other types of data required ,
If it turns into json , There are two ways
serializers.serialize(“json”,QuerySet)
json.dumps(QuerySet)
3.4 Django Run locally , But it cannot be accessed externally
To configure setting.py, Allow address access to
Rerun Django , Add... When running the command 0.0.0.0:8000
3.5 Django Interface data is normally obtained , but vue front end table Data cannot be displayed normally
The cause of the problem is this Point to the problem ,funtion In normal functions this Point to window: So if you need to function Use in a function this object , It needs to be done in advance this Object assigned to other variables