LoginSignup
1
1

More than 1 year has passed since last update.

【超初心者用】PaizaCloud✖Djangoでwebアプリを作る

Posted at

何の記事?

YouTubeの動画を見ながらDjangoでwebアプリを構築しました。
手順の備忘録です。使用するプログラムはpythonです。
https://www.youtube.com/watch?v=nS41IkL13QE&t=1057s

手順

  1. PaizaCloudにログインして新規サーバを作成。言語はDjangoにする

  2. ターミナルから、django-admin startproject django_websiteと入力(django_websiteはプロジェクト名)

  3. pwdcd django_websiteでフォルダを移動

  4. python manage.py runserverで開発用サーバーの立ち上げ

  5. django_website/pycache/settings.pyの28行目、ALLOWED_HOSTS = []となっているところを、ALLOWED_HOSTS = [*]に書き換える

  6. 左の8000をクリックすると、サイトが表示される

  7. ターミナルでpython manage.py startapp websiteと入力してwebsiteというアプリを作成

  8. django_website/pycache/settings.pyのINSTALLED_APPSに新しく追加したアプリ('website')を追加登録

  9. websiteフォルダを右クリックして"templates"フォルダを作り、その中に"index.html"というファイルを作る。

index.html
<h1>Hello, django!</h1>

10: websiteフォルダ内のviews.pyを以下のように書き換える

views.py
from django.views.generic import TemplateView

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

11: websiteフォルダ内にurls.pyを作成し、以下のように記載

urls.py
from django.urls import path
from .views import IndexView

urlpatterns = [
    path('', IndexView.as_view()),
]

12: django_website>pycache>urls.pyを以下に書き換える

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

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

これで晴れて、"Hello, django!"を表示できました。
image.png

フォルダ構成は以下の通りです。
image.png

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