怎么用Django 快速的创建一个最最简易的网站

本文详细介绍了如何使用Django快速创建一个简单的网站,包括安装Django、创建数据库表、设置静态文件和模板,以及后台管理功能的实现。通过实践步骤,读者可以学会从零开始构建一个展示数据的网站。
摘要由CSDN通过智能技术生成

一、Django服务开启

1.python 安装Django

安装过程参考官网

2.cmd命令创建一个project文件夹

django-admin startproject firstsite

3.进入文件夹运行manage.py创建一个app

python manage.py startapp firstapp

4.把app名称加入到settings.py中

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'firstapp'
]

5.运行migrate初始化

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

6.运行runserver 开启服务器

python manage.py runserver

出现以下结果
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 25, 2021 - 17:57:36
Django version 2.2, using settings 'firstsite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

7.此时Django服务器就运行成功了,打开http://127.0.0.1:8000/就可以看到最原始的网页

二、创建数据库中的数据表

1.打开app中的models.py定义一个人员类,有名字和工

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值