django项目问题集锦

1.django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

http://www.bubuko.com/infodetail-3042888.html

如何查看你的库的安装目录:

import 你的库,如aiohttp
aiohttp.__file__

File "/usr/local/python3/lib/python3.6/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 = query.decode(errors='replace')
修改为
query = query.encode(errors='replace')

django版本居然有点小bug,你敢信,大神们,修复下吧,不然每次改django的源码,不好吧!

 

2.ImportError: cannot import name 'python_2_unicode_compatible'

python和django版本不一致造成的

python3 -m django --version

我使用的版本:

django版本:2.0.6
python版本:3.6.5

3.ImportError: cannot import name 'APIView'

解决:

来自于djangorestframework
查看版本pip3 list |grep 'djangorestframework'

调整django和python版本

https://blog.csdn.net/yunfeiyang520/article/details/80751420
python3.6.5安装
安装make&makeinstall的时候出了点问题

https://blog.csdn.net/shenyuan12/article/details/107928660

安装依赖出问题,需要挨个安装
No match for argument: db4-devel
No match for argument: libpcap-devel
因为最新linux使用的是centos8,所以部分依赖安装不了,需要安装epel
最新centos8好多镜像装不了,无奈,将阿里云操作系统换回centos7把

 

4.部分pip超时安装

1.
 
    pip install -i https://pypi.douban.com/simple <需要安装的包>
    比如:
    pip install -i https://pypi.douban.com/simple requests
 
国内源:
 
    http://pypi.douban.com/ 豆瓣
    http://pypi.hustunique.com/ 华中理工大学
    http://pypi.sdutlinux.org/ 山东理工大学
    http://pypi.mirrors.ustc.edu.cn/ 中国科学技术大学
 
2.pip3 install zmq==0.0.0 --default-timeout=1000

5.启用AWSGI的时候(websocket用到):

django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'websocket_demo.settings')
django.setup()
 
from channels.auth import AuthMiddlewareStack
from django.core.asgi import get_asgi_application
# Import other Channels classes and consumers here.
from channels.routing import ProtocolTypeRouter, URLRouter
# from apps.websocket_app.urls import websocket_urlpatterns
from websocket_demo.urls import websocket_urlpatterns
 
# application = get_asgi_application()
application = ProtocolTypeRouter({
    # Explicitly set 'http' key using Django's ASGI application.
    "http": get_asgi_application(),
    'websocket': AuthMiddlewareStack(
        URLRouter(
            websocket_urlpatterns
        )
    ),
})

注意:django.setup()要置顶,不能在底部,否则使用daphne启动会报上面的错误。

解决问题的链接:

https://blog.csdn.net/shykevin/article/details/114681343

 

6.Error: Another program is already listening on a port that one of our HTTP servers is configured to

supervisord -c /etc/supervisord.conf出现这个问题

ps -aux|grep supervisord 查看进程代号
kill -9 进程代号
或者
unlink /tmp/supervisor.sock

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值