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



总结

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

相关推荐
猫头虎24 分钟前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven
八零后琐话1 小时前
干货:程序员必备性能分析工具——Arthas火焰图
开发语言·python
青春不朽5122 小时前
Scrapy框架入门指南
python·scrapy
MZ_ZXD0013 小时前
springboot旅游信息管理系统-计算机毕业设计源码21675
java·c++·vue.js·spring boot·python·django·php
全栈老石3 小时前
Python 异步生存手册:给被 JS async/await 宠坏的全栈工程师
后端·python
梨落秋霜3 小时前
Python入门篇【模块/包】
python
阔皮大师4 小时前
INote轻量文本编辑器
java·javascript·python·c#
小法师爱分享4 小时前
StickyNotes,简单便签超实用
java·python
深蓝电商API4 小时前
处理字体反爬:woff字体文件解析实战
爬虫·python