1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【学習メモ】Djangoでのアプリの作り方〜Hello Worldを表示させるまで〜

Posted at

Qita
の続き

#アプリを作る

$ python manage.py  startapp picblog

#settings.pyのINSTALED_APPSにアプリを追加


INSTALED_APPS =[
    'picblog.apps.PicblogConfig',
]

#htmlをつくる

picblogの中にtemplateフォルダを作り、その中に新たにpicblogというフォルダを作る。
ここにhtmlを書くようにする。

作ったtemplate/picblogフォルダの中に、base.htmlとhome.htmlを作る。

home.htmlに表したい文字をかく

hello world

#views.pyを設定

from django.views.generic import TemplateView

class Home(TemplateView):
    template_name='picblog/home.html'

#urlをつなぐ

configのurls.pyを開く

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
   path('',include('picblog.urls')),
   path('admin/', admin.site.urls),
]

picblogアプリの中にurls.pyを作る

Homeはviews.pyで書いたクラス名


from django.urls import path
from . import views

app_name='picblog'

urlpatterns=[
    path('',views.Home.as_view(),name='home'),
]

#ランサーバーする

$python manage.py runserver

更新されたwebページにhello worldが出たらOK

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?