常用命令
- 生成应用
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
-
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)] }
-
ERROR: 访问url报错Forbidden (CSRF cookie not set.): xxx
SOLUTION: 注释掉setting.py里的下列语句