我正在尝试创建一个允许用户上传文件的应用。我想创建一个处理文件上传的模型。
from django import forms
class UploadFileForm(forms.Form):
title = forms.CharField(max_length=50)
file = forms.FileField()
但是当我执行syncdb时遇到以下错误。
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/site-packages/django/core/management/validation.py", line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/roy/projects/qsourcing/qsl/models.py", line 5
title = forms.CharField(max_length=50) file = forms.FileField()
^
SyntaxError: invalid syntax
答案 0 :(得分:3)
从底部开始阅读你的回溯:
File "/home/roy/projects/qsourcing/qsl/models.py", line 5
title = forms.CharField(max_length=50) file = forms.FileField()
^
SyntaxError: invalid syntax
在这种情况下, models.py 的第5行存在问题。您错过了一个新行
答案 1 :(得分:0)
Soner是对的。此问题很可能是由格式错误引起的。在我从教程或博客中复制代码然后将其直接粘贴到我的项目中之后,我几次遇到此错误。如果在复制和粘贴教程或博客中的代码后看到此错误,只需删除粘贴的代码并手动键入代码即可。
最佳,