ํ๋ก์ ํธ ๋ฐ APP ์ด๊ธฐ ์ค์
$ django-admin startproject [project name]
$ python manage.py startapp [app name]
# urls.py
from django.contrib import admin
from django.urls import path, include
# forms.py
from django import forms
# models.py
from django.db import models
# auth
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth.decorators import login_required
from django.contrib.auth import get_user_model, login, logout
from django.contrib.auth.models import User
# views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.views.decorators.http import require_POST
from django.conf import settings
from django.contrib import admin
$ touch .gitignore
$ python -m venv venv
$ source venv/bin/activate
$ python -m pip install --upgrade pip
$ pip install django==2.1.15 django_extensions django_bootstrap4
$ pip freeze > requirements.txt
$ django-admin startproject django_additional .
$ pip install django-allauth
...
INSTALLED_APPS = [
# pip
'django_extensions',
'bootstrap4',
'bootstrap_pagination',
'mathfilters',
# django original
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', #new
'storages',
# my apps
'articles',
'accounts',
# allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.github',
]
...
# allauth setting
AUTHENTICATOIN_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SITE_ID =1
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
}
},
'github': {
'SCOPE': [
'user',
'repo',
'read:org',
],
}
}
urlpatterns = [
...
path('accounts/', include('accounts.urls')),
# ์ฐ๋ฆฌ๊ฐ ์ ์ํ accounts.url ์๋์
path('accounts/', include('allauth.urls')),
...
]
SOCIALACCOUNT_PROVIDERS = {
'github': {
'SCOPE': [
'user',
'repo',
'read:org',
],
}
}
$ pip install django-bootstrap-pagination
INSTALLED_APPS = (
'bootstrap_pagination',
)
{% load bootstrap_pagination %}
...
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}