bifangback

bifangback-django项目建立

2020-12-28  本文已影响0人  万州客

又开始慢慢积累。

一,安装django

pip install django==3.1.4
如果已安装django,输出如下:

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: django==3.1.4 in d:\python38\lib\site-packages (3.1.4)
Requirement already satisfied: asgiref<4,>=3.2.10 in d:\python38\lib\site-packages (from django==3.1.4) (3.2.10)
Requirement already satisfied: pytz in d:\python38\lib\site-packages (from django==3.1.4) (2020.4)
Requirement already satisfied: sqlparse>=0.2.2 in d:\python38\lib\site-packages (from django==3.1.4) (0.4.1)

二,新建一个项目

django-admin startproject bifangback
此时,会生成django项目的基本文件结构

2020-12-28 21_49_00-bifangback.png

三,合并数据库

开始执行
python manage.py makemigrations
开始只有系统默认的数据库表,所以这里没有任何数据库变化。
输出如下:

No changes detected

python manage.py makemigrations这个命令是记录我们对models.py的所有改动,并且将这个改动迁移到migrations这个文件下
然后执行:
python manage.py migrate
输出:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

python manage.py migrate 命令时 这条命令的主要作用就是把这些改动作用到数据库也就是执行migrations里面新改动的迁移文件更新数据库,比如创建数据表,或者增加字段属性

四,建立超级管理员

接下来,我们建立一个超级管理,用于admin数据库管理后台
python manage.py createsuperuser
在输出中,按提示,即可完成

Username (leave blank to use 'ccc'): admin
Email address: admin@demo.com
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

五,启动django服务

python manage.py runserver
如果一切正常,输出如下:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
December 28, 2020 - 21:55:32
Django version 3.1.4, using settings 'bifangback.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

也可以使用python manager.py runserver --host 0.0.0.0 --port 9008命令,来指定监听IP和端口。

六,查看启动网页

访问http://127.0.0.1:8000/


2020-12-28 21_57_33-Django_ the Web framework for perfectionists with deadlines..png

七,查看admin后台管理

访问http://127.0.0.1:8000/admin/
输出超级管理帐号和密码,即可查看后台数据库。

2020-12-28 21_59_08-Site administration _ Django site admin.png
上一篇下一篇

猜你喜欢

热点阅读