Django-4.2博客开发教程:欢迎页面(三)
1.python虚拟环境搭建virtualenv
2.Django-4.2博客开发教程:欢迎页面(三)
3.Django-4.2博客开发教程:需求分析并确定数据表(四)4.Django-4.2博客开发教程:创建项目(一)5.Django-4.2博客开发教程:初始化应用配置(二)6.Django-4.2博客开发教程:维护后台数据admin模块(六)7.Django-4.2博客开发教程:使用第三方库美化后台页面,丰富文章内容(七)8.Django-4.2博客开发教程:URL与视图函数(八)9.Django-4.2博客开发教程:初识模板(九)10.Django-4.2博客开发教程:数据库操作-页面动态展示数据库中的数据(十)1.首先进入Python虚拟环境:
cmd 窗口cd 到 项目下的 cd D:\git_lab\myblog\Scripts>,执行激活 activate
变成如下
(myblog) D:\git_lab\myblog\Scripts>
2.执行数据迁移:
首次会自动创建sql文件,创建数据库表。
(myblog) D:\git_lab\myblog>py manage.py makemigrations System check identified some issues: WARNINGS: ?: (staticfiles.W004) The directory 'D:\git_lab\myblog\static' in the STATICFILES_DIRS setting does not exist. No changes detected (myblog) D:\git_lab\myblog>py manage.py migrate System check identified some issues: WARNINGS: ?: (staticfiles.W004) The directory 'D:\git_lab\myblog\static' in the STATICFILES_DIRS setting does not exist. 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 (myblog) D:\git_lab\myblog>
3.创建管理帐号和密码
1 | python manage.py createsuperuser |
(myblog) D:\git_lab\myblog>python manage.py createsuperuser System check identified some issues: WARNINGS: ?: (staticfiles.W004) The directory 'D:\git_lab\myblog\static' in the STATICFILES_DIRS setting does not exist. 用户名 (leave blank to use 'administrator'): admin 电子邮件地址: admin@qq.com Password: Password (again): 密码长度太短。密码必须包含至少 8 个字符。 这个密码太常见了。 密码只包含数字。 Bypass password validation and create user anyway? [y/N]: y Superuser created successfully.
1 | |
4.启动服务
1 | python manage.py runserver 127.0.0.1:8080 #指定IP和端口,然后通过浏览器访问这个地址 |
(myblog) D:\git_lab\myblog>python manage.py runserver 127.0.0.1:8080 Watching for file changes with StatReloader Performing system checks... System check identified some issues: WARNINGS: ?: (staticfiles.W004) The directory 'D:\git_lab\myblog\static' in the STATICFILES_DIRS setting does not exist. System check identified 1 issue (0 silenced). July 17, 2023 - 17:29:20 Django version 4.2.3, using settings 'myblog.settings' Starting development server at http://127.0.0.1:8080/ Quit the server with CTRL-BREAK.
上面访问成功是自带的,我们可以自己做一个欢迎页:
首先,打开打开bolg目录下的views.py文件,在里面输入:
1 2 3 4 5 6 | myblog /blog/views .py from django.http import HttpResponse def hello(request): return HttpResponse( 'hello!' ) |
再打开myblog目录下的urls.py文件,在文件里添加两行代码:
1 2 3 4 5 6 7 8 9 | myblog / myblog / urls.py from django.contrib import admin from django.urls import path from blog import views urlpatterns = [ path( 'admin/' , admin.site.urls), path('', views.hello), ] |
以上两个文件写成这个样子,你就可以直接刷新看结果了。
访问: http://127.0.0.1:8080/admin
输入上面新建的超级管理员,就可以登录管理用户信息了。
1 | |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧