Python全系列 教程
3567个小节阅读:5929.3k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
创建项目
xxxxxxxxxx
django-admin startproject demo
增加子应用
xxxxxxxxxx
python manage.py startapp deploy_app
添加子应用与ckeditor子应用
xxxxxxxxxx
# settings.py
INSTALLED_APPS = [
'ckeditor',
'deploy_app',
'...'
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
设置模板目录
xxxxxxxxxx
# settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
增加逻辑视图
xxxxxxxxxx
# views.py
from django.shortcuts import render
# Create your views here.
def index(request):
if request.method =='GET':
return render(request, 'index.html')
增加路由
xxxxxxxxxx
# urls.py
from django.urls import path
from . import views
urlpatterns = [
path('index/', views.index, name='index'),
]
设置页面
加载静态文件与设置表单
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
{% load static %}
</head>
<body>
<h2>Django的部署项目</h2>
<img src="{% static 'imgs/tu1.png'%}" alt="">
</body>
</html>
错误
django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
解决方案
这个错误通常是由于Django使用的SQLite数据库版本过低导致的。SQLite 3.8.3或更高版本才支持deterministic=True参数。
要解决这个问题,你可以尝试以下方法:
- 升级SQLite数据库:你可以通过升级SQLite数据库到3.8.3或更高版本来解决这个问题。
- 使用其他数据库
错误
DisallowedHost at /
解决方案
修改settings.py
ALLOWED_HOSTS = ["*"]