• python-Django框架


    常用命令

    1. 生成应用

    python manage.py start app(app_name)
    2. 开启服务器

    python manage.py runserver 0.0.0.0:8001
    3. 声称以及修改数据模型

    python manage.py makemigrations app(app_name)
    4. 数据库模型移植

    python manage.py migrate
    5. 使用管理界面之前建立管理员用户(必须在cmd下运行)

    python manage.py createsuperuser

    ERROR

    1. ERROR:在使用python虚环境(安装了django)的情况下运行manage.py出错

      I:codepythonwebdjangodjango0510>I:codepythonwebdjangodjangoenvScriptspython manage.py 8001
      Traceback (most recent call last):
        File "manage.py", line 10, in <module>
          execute_from_command_line(sys.argv)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangocoremanagement\__init__.py", line 350, in execute_from_command_line
          utility.execute()
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangocoremanagement\__init__.py", line 324, in execute
          django.setup()
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjango\__init__.py", line 18, in setup
          apps.populate(settings.INSTALLED_APPS)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangoapps
      egistry.py", line 108, in populate
          app_config.import_models(all_models)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangoappsconfig.py", line 202, in import_models
          self.models_module = import_module(models_module_name)
        File "h:64softpython27Libimportlib\__init__.py", line 37, in import_module
          __import__(name)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangocontribauthmodels.py", line 297, in <module>
          class AbstractUser(AbstractBaseUser, PermissionsMixin):
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangodbmodelsase.py", line 251, in __new__
          new_class.add_to_class(field.name, new_field)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangodbmodelsase.py", line 299, in add_to_class
          value.contribute_to_class(cls, name)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangodbmodelsfields\__init__.py", line 672, in contribute_to_class
          cls._meta.add_field(self)
        File "I:codepythonwebdjangodjangoenvlibsite-packagesdjangodbmodelsoptions.py", line 312, in add_field
          self.local_fields.insert(bisect(self.local_fields, field), field)
        File "h:64softpython27Libfunctools.py", line 56, in <lambda>
          '__lt__': [('__gt__', lambda self, other: other < self),
        ......
        File "h:64softpython27Libfunctools.py", line 56, in <lambda>
          '__lt__': [('__gt__', lambda self, other: other < self),
      RuntimeError: maximum recursion depth exceeded while calling a Python object
      

      SOLUTION: 修改h:64softpython27Libfunctools.py里的convert,如下

      convert = {
              '__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
                         ('__le__', lambda self, other: self < other or self == other),
                         ('__ge__', lambda self, other: not self < other)],
              '__le__': [('__ge__', lambda self, other: not self <= other or self == other),
                         ('__lt__', lambda self, other: self <= other and not self == other),
                         ('__gt__', lambda self, other: not self <= other)],
              '__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
                         ('__ge__', lambda self, other: self > other or self == other),
                         ('__le__', lambda self, other: not self > other)],
              '__ge__ ': [('__le__', lambda self, other: (not self >= other) or self == other),
                         ('__gt__', lambda self, other: self >= other and not self == other),
                         ('__lt__', lambda self, other: not self >= other)]
          }
      
    2. ERROR: 访问url报错Forbidden (CSRF cookie not set.): xxx
      SOLUTION: 注释掉setting.py里的下列语句

  • 相关阅读:
    我的ZigBee学习之路
    php form表单post提交获取不到数据,而使用get提交能获取到数据 的解决办法
    Mac phpstorm破解版安装(简单,有效)
    Mac下phpstorm 浏览器出现 502 bad gateway 解决办法
    LayUI之table数据表格获取行、行高亮等相关操作
    钉钉自定义机器人配合SVN钩子事件进行消息的推送实践
    电脑无故失去焦点,罪魁祸首是谁?终极解决办法
    Java实现的电脑已连接WiFi热点的导入导出小工具 wifi备份
    C# DataGridView自定义分页控件
    C# DataGridView控件禁止拷贝数据
  • 原文地址:https://www.cnblogs.com/fengzzi/p/10037277.html
Copyright © 2020-2023  润新知