• Django-报错解决方法


    无法使用Django新建项目:'django-admin.py’不是内部或外部命令
    找到site-packages/django/bin(如 D:Program FilesAnaconda3Libsite-packagesdjangoin),把这个路径加入系统环境变量中。

    error: unrecognized arguments: getall
    原因:django版本和代码里的requirements.txt要求的不符
    解决:重装django制定版本的代码

    要用 pip 安装指定版本的 Python 包,只需通过 == 操作符 指定
    pip install robotframework==2.8.7
    将安装robotframework 2.8.7 版本。

    ‘WSGIRequest’ object has no attribute ‘user’
    这是Django版本的问题,
    1.9之前,中间件的key为MIDDLEWARE_CLASSES,
    1.9之后,为MIDDLEWARE。
    所以在开发环境和其他环境的版本不一致时,要特别小心,会有坑。需要在settings里面把MIDDLEWARE改为MIDDLEWARE_CLASSES 即可

    TypeError at / ‘bool’ object is not callable
    使用 Django自带的 auth 用户验证功能,编写函数,使用 is_authenticated 检查用户是否登录报错

    def index(request, pid=None, del_pass=None):
      if request.user.is_authenticated():
        username = request.user.username
        useremail = request.user.email
      messages.get_messages(request)
      template = get_template('index.html')
      html = template.render(context=locals(), request=request)
      return HttpResponse(html)

    查询相关资料,发现 is_authenticated 是属性而不是方法,我们应该把括号去掉,这样就没什么问题了。

    将 if request.user.is_authenticated(): 改为 if request.user.is_authenticated:

    错误编码1050

    python manage.py migrate myapp --fake # 数据库表结构同步成功

    错误编码1146
      1.同步数据库
        项目建起来后,同步数据库,加入自定义的app 

    python manage.py syncdb

      2.创建初始的迁移脚本

    python manage.py makemigrations appname

      3.同步迁移数据库    

    python manage.py migrate appname

    user.User.basemodel_ptr: (fields.E300) Field defines a relation with model ‘BaseModel’, which is either not installed, or is abstract.

  • 相关阅读:
    1124 vue路由配置初级实践&和npm run dev干嘛了
    1130 携程网焦点图+导航栏,flex布局实践
    1124 在vscode中快速创建vue模板
    122 携程网案例flex布局第三部分
    128 手撸轮播组件瞬时切换版本,布局部分
    1125 vscode自定义快捷键扩展选择单词等
    124 本地服务器搭建
    1128 defineProperty中getter和setter的用法
    2216 怎么快速打开powershell
    Visual Studio 2010的网站局域网发布功能(Publish)
  • 原文地址:https://www.cnblogs.com/Python-XiaCaiP/p/10098476.html
Copyright © 2020-2023  润新知