1
class FileUploadModel(models.Model):
    title = models.CharField(max_length=50)
    uploaded_file = models.FileField(upload_to = 'bose')

错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 231, in execute
    self.validate()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 30, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 158, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/bose/DJANGO/blog/blog/models.py", line 22
    uploaded_file = models.FileField(upload_to = 'bose')

IndentationError: unindent does not match any outer indentation level

我哪里错了?

4

2 回答 2

9

好吧,如果您将代码直接复制到编辑框中,那么您的问题是您混合了制表符和空格。问题源中的title行前面有一个制表符,而下一行前面有四个空格。

有关更多信息,请参阅此问题及其答案。-t如果您希望 Python 在您同时使用制表符和空格时发出警告,则可以使用该选项。

于 2012-04-26T21:32:00.533 回答
0

如果您使用 Komodo 编辑器,则可以按照类似错误消息之一中的建议进行操作:

1) 全选,例如 Ctrl + A

2)转到代码 - >取消区域

3)仔细检查您的缩进是否仍然正确,保存并重新运行您的程序。

我正在使用 Python 3.4.2

于 2014-12-02T19:56:49.757 回答