2
5

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を使ったWEBアプリケーションの開発【Admin画面の作成編】

Last updated at Posted at 2020-10-03

モデル定義編の続き
Admin画面の確認

Djangoの管理画面を確認します。
今までは、http://127.0.0.1:8000/posts/を開いていましたが、postsの部分をadminに変更してhttp://127.0.0.1:8000/admin/を開いてみると下記の画面が確認できます。
この状態では、まだログインすることができませんので、次にアカウントの作成を行います。
admin.png

Adminアカウントの作成

コマンドプロンプトで下記を実行します。

$ python3.6 manage.py createsuperuser

ユーザー名 (leave blank to use 'kazunari'): (好きなユーザー名を入力)
メールアドレス: ************@gmail.com
Password: 
Password (again): 
Superuser created successfully.

ユーザー名・メールアドレス・パスワードを入力し、再度パスワードを入力することで作成が完了です。

Adminページへのログイン

Admin画面で先程登録したアカウントを使ってログインしてみると、下記の管理画面が表示されます。
login.png

管理画面にアプリケーションを表示させる

管理画面に作成したアプリケーション(Posts)を表示させます。
posts > template 内のadmin.pyに追記していきます。

admin.py
from django.contrib import admin
from .models import Post #追加した行

admin.site.register(Post) #追加した行

models.pyからPostクラスをインポートします。
そして、Admin画面へ追加するプログラムを記述します。

そうすることにより、管理画面からposts機能にアクセスし、データの追加や編集、削除を行うことができるようになります。
アプリケーション表示.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?