【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'   # 中文



总结

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

相关推荐
孟健7 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞8 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽11 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程15 小时前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪15 小时前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook16 小时前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统
python
前端付豪1 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽1 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战1 天前
Pydantic配置管理最佳实践(一)
python