[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 추가
MIDDLEWARE = [
...
'corsheaders.middleware.CorsMiddleware',
]
가장 하단에 추가
##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())
]