zoukankan      html  css  js  c++  java
  • 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里的下列语句

  • 相关阅读:
    泛型的内部原理:类型擦除以及类型擦除带来的问题
    内部类访问局部变量的时候,为什么变量必须加上final修饰
    Web 测试经验总结
    故障测试
    智能硬件产品的测试经验总结
    web端测试和移动端测试的区别小记
    MVC模式介绍
    重定向与转发
    MySQL权限管理分配
    pt-heartbeat工具监控MySQL复制延迟
  • 原文地址:https://www.cnblogs.com/fengzzi/p/10037277.html
Copyright © 2011-2022 走看看