Django使用问题怎么解决
本篇内容介绍了“Django使用问题怎么解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
Django REST framework
出错信息:ImportError: cannot import name 'url' from 'django.conf.urls'
django在4.0已经废弃了django.conf.urls.url()
(django.conf.urls.url() was deprecated in Django 3.0, and is removed in Django 4.0+.)
在urls.py里面,用
from django.urls import re_path as url
代替
from django.conf.urls import url
启动时,Invalid HTTP_HOST header: '
修改创建项目时生成的setting.py文件
将ALLOWED_HOSTS = []改为ALLOWED_HOSTS = ['*']
安装记录
升级SQLite
运行#python3 manage.py runserver 出错,错误信息最底一行
django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
需要升级SQLite
#下载3.39.3版
wget https://www.sqlite.org/2022/sqlite-autoconf-3390300.tar.gz
# 编译
tar zxvf sqlite-autoconf-339300.tar.gz
cd sqlite-autoconf-3339300
./configure --prefix=/usr/local
make && make install
# 替换系统低版本 sqlite3
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
echo "/usr/local/lib" > /etc/ld.so.conf.d/sqlite3.conf
ldconfig
sqlite3 -version
升级到3.39.3,依然报上述错误,只能采用下述办法:
#安装pysqlite3
pip3 install pysqlite3
#修改文件
vi /usr/local/python3.9.9/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py
#from sqlite3 import dbapi2 as Database #注释它
from pysqlite3 import dbapi2 as Database #新加这段代码
启动正常
相关文章