天天看点

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:\code\python\web\django\django0510>I:\code\python\web\django\djangoenv\Scripts\python manage.py 8001
    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
        utility.execute()
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\core\management\__init__.py", line 324, in execute
        django.setup()
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\__init__.py", line 18, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\apps\registry.py", line 108, in populate
        app_config.import_models(all_models)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\apps\config.py", line 202, in import_models
        self.models_module = import_module(models_module_name)
      File "h:\64soft\python27\Lib\importlib\__init__.py", line 37, in import_module
        __import__(name)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\contrib\auth\models.py", line 297, in <module>
        class AbstractUser(AbstractBaseUser, PermissionsMixin):
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\db\models\base.py", line 251, in __new__
        new_class.add_to_class(field.name, new_field)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\db\models\base.py", line 299, in add_to_class
        value.contribute_to_class(cls, name)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\db\models\fields\__init__.py", line 672, in contribute_to_class
        cls._meta.add_field(self)
      File "I:\code\python\web\django\djangoenv\lib\site-packages\django\db\models\options.py", line 312, in add_field
        self.local_fields.insert(bisect(self.local_fields, field), field)
      File "h:\64soft\python27\Lib\functools.py", line 56, in <lambda>
        '__lt__': [('__gt__', lambda self, other: other < self),
      ......
      File "h:\64soft\python27\Lib\functools.py", line 56, in <lambda>
        '__lt__': [('__gt__', lambda self, other: other < self),
    RuntimeError: maximum recursion depth exceeded while calling a Python object
               
    SOLUTION: 修改h:\64soft\python27\Lib\functools.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里的下列语句

    python-Django框架
ฅ平平庸庸的普通人ฅ
上一篇: python-爬虫
下一篇: hadoop安装