LoginSignup
0
1

DjangoでHello,world表示まで(自分用)

Posted at

前回の記事の続きになります。

Djangoを立ち上げる〜Hello,world表示までの自分用メモ

ローカル環境に保存していた勉強ログをQiitaにあげていく自分用のメモです

開発環境

OS:mac
エディタ:vscode
Django:4.1.0
Python:3.10.9

index.htmlを表示していく過程を記す

manage.pyがあるディレクトリにてテンプレートファイルをまとめる
templatesディレクトリを作成して、その中にindex.htmlを作成
<h1>Hello,world!</h1>とでも書いておく

templatesの位置を教えてあげる

setting.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
    {
        'DIRS': [BASE_DIR,'templates'],#追加
    },
]

views.py

views.py
from django.views.generic import TemplateView

class IndexView(TemplateView):
    template_name='index.html'

プロジェクトのurls.pyにアプリの方のurls.pyを見るように設定

urls.py(プロジェクト)
from django.contrib import admin
from django.urls import path,include#

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('アプリ名.urls')),#
]

アプリのurls.pyを設定

urls.py(アプリ)
from django.urls import path
from .views import IndexView

urlpatterns = [
    path('',IndexView.as_view(),name='index'),
]
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1