程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

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

  • Start again Django

python manage.py runsslserver --certificate /Users/cqa/Desktop/Django-test/venv/lib/python3.10/site-packages/sslserver/certs/development.crt --key /Users/cqa/Desktop/Django-test/venv/lib/python3.10/site-packages/sslserver/certs/development.key

3.2 crsf Certification issues

  • 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

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved