【问题标题】:python django iam stack in this part of code shown below .error displayed un IndentationError: unindent does not match any outer indentation levelpython django iam stack 在这部分代码如下所示。错误显示 un IndentationError: unindent does not match any external indentation level
【发布时间】:2017-02-24 07:34:27
【问题描述】:
from __future__ import unicode_literals

from django.db import models

# Create your simplesite models here.

class simplesite(models.Model):
    name=models.CharField(max_length=100)
    due_date=models.DateTimeField()

#simplest app model

class simplest(models.Model):
    simple_site=models.foreignkey(simplesite)
    name=models.CharField(max_length=100)
    due_date=models.DateTimeField()

这是我运行此命令时显示的错误:python .\manage.py makemigrations simplest

PS C:\django\simplesite> python .\manage.py makemigrations simplest
    Traceback (most recent call last):
File ".\manage.py", line 22, in <module>
        execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
        utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 341, in execute
        django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
    app_config.import_models(all_models)
File "C:\Python27\lib\site-packages\django\apps\config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
File "C:\django\simplesite\simplest\models.py", line 9
    due_date=models.DateTimeField()
                                  ^
IndentationError: unindent does not match any outer indentation level

请帮助我在那个地方的堆栈。我是 python django 框架的初学者

【问题讨论】:

    标签: python django


    【解决方案1】:

    您必须将编辑器配置为按制表符而不是制表符的 4 个空格,因为 python 的四个空格与一个制表符不同。

    您必须确保所有代码都使用四个空格的代码

    【讨论】:

    • 如何使用 pycharm2016.2.3 配置我的 editor.iam
    • 有一点guide你可以配置pycharm来显示插入空格的点,你可以找到有缩进问题的行
    【解决方案2】:

    这是一个基本的 Python 语法问题。确保您没有在缩进中混用空格和制表符。

    【讨论】:

    • ** 我已经检查并仍然显示相同的错误**
    • 'from future import unicode_literals from django.db import models # 在此处创建您的简单站点模型。 class simplesite(models.Model): name=models.CharField(max_length=100) due_date=models.DateTimeField() #simplest app model class simple(models.Model): simple_site=models.foreignkey(simplesite) name=models.CharField (max_length=100) due_date=models.DateTimeField() '
    猜你喜欢
    • 2022-11-27
    • 2016-07-09
    • 1970-01-01
    • 2013-05-14
    • 2012-12-13
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多