Python(Django)遇到的问题及解决方法

问题一

因为已经有程序占用了Django的默认端口了,所以只要这么启动项目,81是使用的端口,然后访问即可http://127.0.0.1:81/

解决:

 


 

问题二

TypeError: not enough arguments for format string

出现这类问题,主要是字符串中包含了%号,python 认为它是转移符,而实际我们需要的就是%, 这个时候,可以使用%%来表示

错:

Train = train.objects.raw(

"select * from front_train where R_id in (select R_id from front_route where R_startcity like '%startaddr%'or R_startplace like '%startaddr%')")

对:

Train = train.objects.raw(

"select * from front_train where R_id in (select R_id from front_route where R_startcity like '%%" + startaddr + "%%'or R_startplace like '%%" + startaddr + "%%')")

 


 

问题三

时区的问题,Django 默认使用的是 UTC 世界协调时,又叫世界统一时间。中国的时间与 UTC 的时差是+8小时,也就是中国时间=UTC+8。

解决:

settings.py设置:USE_TZ = False , TIME_ZONE = ‘Asia/Shanghai‘ , 则使用上海的 UTC 时间

 


 

问题四

ImportError: 'module' object has no attribute 'check_specifier'

解决:

升级setuptools的版本

pip install --upgrade setuptools==30.1.0

 

 


 

问题五

ImportError:No module named import_export.admin 

解决:

安装django-import-export

pip install django-import-export

 

猜你喜欢

转载自www.cnblogs.com/G-MingYin/p/10449437.html