Django建站过程遇到的问题

1 Django和MySQL不兼容:

【现象】:在命令行中输入py manage.py runserver后提示出如下错误

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

这是因为Django对于mysql是不兼容的,而且你应该已经下载了pymysql

【解决】:

  1. 首先确定你在__init.py__文件中有输入如下代码:
import pymysql
pymysql.install_as_MySQLdb()
  1. 其次找到出现问题的文件
    在这里插入图片描述
    就是错误提示中的base.py文件,然后对这个文件进行编辑。找到如下语句,然后将这个if语句注释掉就可以了。
# 之前的代码
version = Database.version_info
if version < (1, 3, 13):
    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

# 修改之后的代码:
version = Database.version_info
# if version < (1, 3, 13):
#     raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

2 URL中没东西

【现象】:

raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module '....urls' from '...'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

这是由于你的urls.py文件中没有设置任何的路由导致的,需要在其中简答设置一个路由。

3 decode问题

【现象】:

File "C:\Users\username\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
    query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'

【解决】:

#原代码:
query = getattr(cursor, '_executed', None)
if query is not None:
     query = query.decode(errors='replace')
return query
 
#修改为:
query = getattr(cursor, '_executed', None)
if query is not None:
     query = query.encode(errors='replace')
return query

即,将decode修改为encode,此解决方法参考在Django框架中偶遇报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法_亭有枇杷树

4 Django的admin密码问题

在初始的admin管理界面,需要我们自己设定账号和密码,具体流程如下:
Django初始化话admin账号和密码_NTopic

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值