바뀜
둘러보기로 가기
검색하러 가기
30번째 줄:
30번째 줄:
− +
37번째 줄:
37번째 줄:
− +
− +
− +
+
+
+
+
+
+
− +
64번째 줄:
70번째 줄:
− +
+
89번째 줄:
96번째 줄:
− +
128번째 줄:
135번째 줄:
− +
→test 앱 만들기
|생성
|생성
|django-admin startapp testapp
|django-admin startapp testapp
|프로젝트 디렉터리 안에서 실행.
|프로젝트 디렉터리 안에서 실행. testapp이라는 앱을 만든다.
그냥 단순히 앱 이름의 디렉터리를 만드는 것 뿐. 기존의 앱을 옮겨온다면 그냥 붙여넣기를 하면 된다.
그냥 단순히 앱 이름의 디렉터리를 만드는 것 뿐. 기존의 앱을 옮겨온다면 그냥 붙여넣기를 하면 된다.
|-
|-
INSTALLSED_APPS 항목에 추가한다.
INSTALLSED_APPS 항목에 추가한다.
|INSTALLSED_APPS 항목 안에 앱이름만 추가해준다.
|INSTALLSED_APPS 항목 안에 앱이름만 추가해준다.
ex) INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',
ex) <syntaxhighlight lang="python">
INSTALLED_APPS = [ 'django.contrib.admin',
'testapp', ]
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testapp', ] # 요거 새로 추가.
</syntaxhighlight>
혹은 앱의 config를 직접 등록한다. (이게 정석)앱디렉터리의 apps.py 안의 Config를 직접 등록. <code>test.apps.TestappConfig</code>형식으로.
혹은 앱의 config를 직접 등록한다.(이게 정석) 앱디렉터리의 apps.py 안의 Config를 직접 등록. <code>test.apps.TestappConfig</code>형식으로.
|}
|}
</syntaxhighlight>
</syntaxhighlight>
|-
|-
|처리할 뷰 지정하기
|앱 안의 urls.py 만들기
처리할 뷰 지정하기
|testapp 안에 urls.py를 만들고 작성한다.
|testapp 안에 urls.py를 만들고 작성한다.
|<syntaxhighlight lang="python">
|<syntaxhighlight lang="python">
def hello(request):
def hello(request):
hello = "hello"
hello = "hello"
context = {"hello": hello}
context = {"hello": hello} # 탬플릿에서 처리할 자료 지정.
print("hello~")
print("hello~")
return render(request, 'test.html', context)
return render(request, 'test.html', context)
{
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'DIRS': [BASE_DIR / 'templates'], # 탬플릿을 찾을 공간을 지정한다.
'APP_DIRS': True,
'APP_DIRS': True,
'OPTIONS': {
'OPTIONS': {