westagram[Mission ]

2009 ワード

[Mission 1]Django初期設定#1

django-admin startproject
project_westagram
conda activate westagram
pip install django
pip install django-cors-headers
django-admin startproject project_westagram
settings.py
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
# 'django.contrib.admin',
# 'django.contrib.auth',
'corsheaders',
...
]
MIDDLEWAREでcsrfとauth関連要素を注記してください.
MIDDLEWARE = [
...
# 'django.middleware.csrf.CsrfViewMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
]
3.ミドルウェアの追加
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
]
  • CORSライセンスの追加
    プロファイルの一番下に次のコードを追加してください.
  • 最下部に追加
    ##CORS
    CORS_ORIGIN_ALLOW_ALL=True
    CORS_ALLOW_CREDENTIALS = True
    CORS_ALLOW_METHODS = (
    'DELETE',
    'GET',
    'OPTIONS',
    'PATCH',
    'POST',
    'PUT',
    )
    CORS_ALLOW_HEADERS = (
    'accept',
    'accept-encoding',
    'authorization',
    'content-type',
    'dnt',
    'origin',
    'user-agent',
    'x-csrftoken',
    'x-requested-with',
    )
    アプリケーションの追加
    python manage.py startapp user
    project_westagram/urls.py
    adminをクリア!
    from django.urls import path,include
    urlpatterns = [
    path('user' ,include(user.urls))
    ]
    vim user/models.py
    from django.db import models
     # Create your models here.
     
     
     class Account(models.Model):
         Name = models.EmailField(max_length=150),
         password = models.CharField(max_length=50)
         class meta:
        db_table = accounts 
    list/urls.py
    from django.urls import path
    from .views import SignupView
    urlpatterns = [
          path('/signup', SignupView.as_view())
                                                                              
          ]