작정하고 장고 1강 - 무엇을 만들 것인지 : Django로 Pinterest 따라하기!
🏆 핀터레스트 레이아웃으로 웹서비스를 만들어보자.$ pyenv virtualenv test123
#버전 스위칭
$ pyenv local test123
(test123)$ pip install django
$ django-admin startproject mysite
Model
View
Template
$ python manage.py startapp accountapp
#in mysite/settings.py
#...
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accountapp',
]
#...
#in accountapp/views.py
from django.http import HttpResponse
def hello_world(request):
return HttpResponse('Hello World!')
#in mysite/urls.py
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('account/', include('accountapp.urls'))
]
#in accountapp/urls.py
from django.urls import path
from accountapp.views import hello_world
app_name = 'accountapp'
urlpatterns = [
path('hello_world', hello_world, name='hello_world'),
]
$ python manage.py runserver
.gitignore
setting.py의 SECRET_KEY
$ pip install django-environ
#in mysite/settings.py
import environ
import os
env = environ.Env(
# set casting, default value
DEBUG=(bool, False)
)
# Set the project base directory
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Take environment variables from .env file
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
DEBUG=on
SECRET_KEY=your-secret-key
DATABASE_URL=psql://user:un-githubbedpassword@127.0.0.1:8458/database
SQLITE_URL=sqlite:///my-local-sqlite.db
CACHE_URL=memcache://127.0.0.1:11211,127.0.0.1:11212,127.0.0.1:11213
REDIS_URL=rediscache://127.0.0.1:6379/1?client_class=django_redis.client.DefaultClient&password=ungithubbed-secret
#in mysite/settings.py
# False if not in os.environ because of casting above
DEBUG = env('DEBUG')
# Raises Django's ImproperlyConfigured
# exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')