LoginSignup
2
3

More than 3 years have passed since last update.

djangoを使って新しくTODOアプリを作る2

Posted at

始めに

前回の記事で書き忘れたので、今回書かせていただきます。
2020年に無職になり、何かしようとおもい2020年夏よりpythonを学習し始めました。プログラミングに関しては経験はほとんどありません。いろんな初学者用の本をやっていて、経験者からUDEMYを使うとよりわかりやすくコスパよく学べるということを教えていただき
今回の講座【徹底的に解説!】Djangoの基礎をマスターして、3つのアプリを作ろう!(Django2版 / 3版を同時公開中です)を受講させていただきました。

今回の記事でやること

1.modelの設定

今回は、下記のようなモデルでいきたいと考えています。(というかmodelってどのタイミングで作るのがいいんでしょうか)

models.py
from django.db import models
class todoModel(models.Model):
   title = models.CharField(max_length=50)
   content = models.textField()
   author = models.CharField(max_length=50)
   dateline = models.DateField()←(締切設定ってこれでいいのでしょうか・・・?)
   now date = models.DateField.auto_now()投稿日
   doit = ?(選択肢を入れる 後で調べる)

2.urls.pyの設定

イメージとしては5画面あるホームページ
サインインページ、ユーザー作成ページ、todolist一覧ページ、詳細ページ、投稿ページ
signup, newuser, list, detail, task という名前で作っていこうとおもいます
それではコードを書いていきます。
プロジェクト側ではなく、アプリ側にurls.pyを作成し、書いていきます。
path("URL名",関数名,name="呼び出し名(?)")みたいな形で書いていきます。

models.py
from django.urls import path , include
from .views import signupfunc, newuserfunc, listfunc, detailfunc, taskfunc 

urlpatterns = [
    path("signup/", signupfunc, name="signup" ),
    path("newuser/", newuserfunc, name="newuser"),
    path("list/", listfunc , name="list"),
    path("detail/", detailfunc , name="detail"),
    path("task/", taskfunc , name="task"),
]

こんな感じでとりあえず描きました。
urlも書いたので次はhtmlを書いていきます。

ホームページのイメージ

ログイン画面のイメージはBOOTSTRAPのサンプルから流用します。
kirinuki.png
https://getbootstrap.jp/docs/5.0/examples/sign-in/
こんな感じでいきたいとおもいます。

リスト画面は次のようにしていきます。
kirinuki2.png

では、共通のフレームのhtmlファイル(今回の名前はbase.html)から作っていきます

base.html
<!doctype html>
<html lang="ja">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->

    {% block customcss %}
    {% endblock customcss %}

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
        integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

    <title>Hello, world!</title>
</head>

{% block header %}
{% endblock header %}

{% block content %}
{% endblock content %}

</html>

イメージとしては、共通事項はbase.htmlにかいて、
block 〇〇のところにそれぞれの要素を書いていくイメージです。
その3ではそれぞれのhtmlとviews.py、model.pyの疑問点を調べて書いていきたいとおもいます

2
3
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
3