2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Template利用方法の演習その1

Posted at

【Udemy】「Python + Django5 Djangoを基礎から応用まで、アプリケーション開発マスターpython付き」の学習記録。

Notionでまとめて、そのままの形でQiitaに投稿できればいいのにな...:pray:

Django 大学陸上部サイトの作成

1. プロジェクト作成:TemplateExam

cd 04_TemplateExam
django-admin startproject TemplateExam

2. アプリケーション作成:TemplateApp

cd TemplateExam
python manage.py startapp TemplateApp

settings.py にアプリケーションを追加

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'TemplateApp',  # アプリケーション名
]

アプリケーションの urls.py を作成

cd TemplateApp
touch urls.py

プロジェクトの urls.py を編集

from django.contrib import admin
from django.urls import path, include  # includeを追加

urlpatterns = [
    path('admin/', admin.site.urls),
    path('app/', include('TemplateApp.urls')),  # アプリケーションのurlsをインクルード
]

TemplateApp の urls.py を記述

from django.urls import path
from . import views  # 同階層のviews.pyをインポート

app_name = 'app'  # アプリケーション名

urlpatterns = [
    path('home', views.home, name='home'),  # home.htmlを表示
    path('members', views.members, name='members'),  # members.htmlを表示
    path('member/<int:num>', views.member, name='member'),  # member.htmlを表示
]
2
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?