Django 第一天

配置urls导包

  from django.urls import path 

  from . import views

  urlpatterns=[

    path('xxx/',views.xxx)

  ]

配置views导包

  from django.shortcuts import render

  from django.http import HttpResponse

  

    

修改urls内容,方便跳转

  from django.contrib import admin

  from django.urls import path,include

  urlpatterns = [

    path('admin/',admin.site.urls),

    path('/',include('polls.urls)),

]

创建app:python mange.py startapp 文件名

跨域请求配置

  INSTALLED_APPS =[

  添加 ‘corsheaders’ ]

  MIDDLEWARE = [ 

  注释掉 ‘django.middleware.csrf.CsrfViewMiddleware’

  再添加‘corsheaders.middleware.CorsMiddleware’

  

  末尾添加:

  CORS_ALLOW_CREDENTIALS = True

  CORS_ORIGIN_ALLOW_ALL = True
  CORS_ORIGIN_WHITELIST = ()
  CORS_ALLOW_METHODS = (
  'DELETE',
  'GET',
  'OPTIONS',
  'PATCH',
  'POST',
  'PUT',
  'VIEW',
  )

  CORS_ALLOW_HEADERS = (
  'XMLHttpRequest',
  'X_FILENAME',
  'accept-encoding',
  'authorization',
  'content-type',
  'dnt',
  'origin',
  'user-agent',
  'x-csrftoken',
  'x-requested-with',
  'Pragma',
  )
原文地址:https://www.cnblogs.com/guohad/p/12070057.html