django 学习 (一) 简单试用
主要记录关于环境搭建的问题
安装django
推荐使用venv,virtualenv 也是一个不错的选择
python -m venv venv
source venv/bin/activate
python -m pip install Django
创建一个简单的project
使用django-admin
django-admin startproject demoapp
效果
运行
python manage.py runserver
包含admin 运行
先执行db 创建
python manage.py migrate
账户创建
python manage.py createsuperuser
重启服务登陆效果
docker 运行
- requirements.txt
Django==3.1.4
- Dockerfile
FROM python:3.8.7-slim
WORKDIR /app
COPY . /app
RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt
EXPOSE 8000
CMD [ "python","manage.py","runserver","0:8000" ]
参考命令
- django-admin
Type 'django-admin help <subcommand>' for help on a specific subcommand.
Available subcommands:
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runserver
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).
- manage.py
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[auth]
changepassword
createsuperuser
[contenttypes]
remove_stale_contenttypes
[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver
说明
django 脚手架工具提供的命令还是比较多的,可以都试试,加深了解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2019-12-30 使用foreman 管理基于Procfile 的应用
2019-12-30 xfs validation inode faild 问题解决
2018-12-30 Gravitee.io Access Management docker-compose运行
2018-12-30 Gravitee.io Access Management 组件
2018-12-30 Gravitee.io alert 引擎架构
2018-12-30 gravitee.io gateway 组件说明
2018-12-30 Gravitee.io 架构