【Django】招聘面试管理01 创建项目&运行项目


文章目录


前言

跟着视频学一学,记录一下。


一、创建项目

照着步骤创建虚拟环境,安装Django等依赖包,创建项目:【Django学习】01 项目创建、结构及命令

bash 复制代码
> django-admin startproject pro_recruitment
> cd pro_recruitment

项目结构:

二、运行项目

bash 复制代码
> python manage.py runserver                # 运行项目,默认以0.0.0.0:8000
> python manage.py runserver 0.0.0.0:8000   # 也可指定端口

访问网页(127.0.0.1:8000 或指定IP:8000 ),可以看到Django的初始页面:

项目运行之后,Django使用默认的SQLite数据库,会在项目的根目录下创建数据库文件db.sqlite3 ,

可在项目settings.py 文件中指定sqlite3文件的路径或更改为其他的数据库引擎。

数据库访问层和Django是松耦合的:数据库的配置也可随时替换;同一套代码,既可以使用sqlite数据库,也可使用MySQL数据库或Oracle数据库。

三、访问后台管理页面

访问链接:http://127.0.0.1:8000/admin

后台登录是需要账号及密码的,但现在尝试输入账号密码却会报错,报错原因是此时尚未迁移数据库以及未创建管理员账号。

先迁移一下数据库:

powershell 复制代码
PS E:\05_Python\Django_Codes\pro_recruitment> python .\manage.py makemigrations
No changes detected
PS E:\05_Python\Django_Codes\pro_recruitment> 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 auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK
PS E:\05_Python\Django_Codes\pro_recruitment>

后创建管理员账号:

powershell 复制代码
PS E:\05_Python\Django_Codes\pro_recruitment> python .\manage.py createsuperuser
Username (leave blank to use 'asdfv'): admin
Email address: admin@123.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is too common.
This password is entirely numeric.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

账号创建完成,再重新运行项目后去后台管理界面上进行登录,此时就能正常进入:

四、配置项

settings.py是项目的配置文件,其中包含了语言设置、数据库设置、模板文件设置等等。

设置中文

python 复制代码
LANGUAGE_CODE = 'zh-hans'   # 中文



总结

项目的创建与运行,没啥问题,掌握常用的命令即可;同时需要加强排错能力,在遇到报错时能快速定位并解决。

相关推荐
万化冥合26 分钟前
怎么批量把 Word 转 PDF?
python·pdf·c#·word
~城南花已开~30 分钟前
Redfish 事件接收服务搭建指南(Ubuntu Server 实测)
linux·服务器·python·ubuntu
fengyangaiGEO31 分钟前
如何通过GEO优化实现外贸B2B询盘增长?
人工智能·python
jianxuan42 分钟前
Spring Boot + Maven 接入 Allatori:从普通打包到可选混淆发布
spring boot·python·maven
不一样的故事12643 分钟前
Prompt 工程(Prompt Engineering)
前端·人工智能·python
我命由我1234544 分钟前
6-2.Python 异常处理 - 异常捕获(捕获指定异常、常见异常类型、异常信息)
java·运维·开发语言·python·http·https·java-ee
zh路西法1 小时前
【模型式强化学习】(三):MBPO——短轨迹生成与模型数据驱动的策略优化
python·强化学习·pe·sac·pets·mbpo·mbrl
Angeldream1231 小时前
第 9 章 医学影像项目实战
大数据·图像处理·人工智能·python·医学影像处理
ZhengEnCi1 小时前
一亿条数据取前100条完全指南:从全量排序到分块流式最小堆的4种解法实测
python·算法·排序算法
2601_967979121 小时前
AccessControl 5.4 macOS Python 3.9 版本安装包
python·macos·security·accesscontrol·permissions