Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在django中保存文件失败_Django - Fatal编程技术网

在django中保存文件失败

在django中保存文件失败,django,Django,这基本上是一个复制品,但答案不适合我 我试过这个: from django.core.files.storage import FileSystemStorage fs = FileSystemStorage(location='/a/legitimate/path) class UploadedFile(models.Model): title = models.CharField(max_length=50) file = models.FileField(storage

这基本上是一个复制品,但答案不适合我

我试过这个:

from django.core.files.storage import FileSystemStorage

fs = FileSystemStorage(location='/a/legitimate/path)

class UploadedFile(models.Model):
    title = models.CharField(max_length=50)
    file = models.FileField(storage=fs,upload_to='fits/')

class UploadFileForm(forms.ModelForm): 
    class Meta: 
        model = UploadedFile 
        fields = ('title', 'file') 
但在我看来,当我这样做时:

    form = UploadFileForm(request.POST,request.FILES)
    if form.is_valid(): 
        form.save()
我得到以下错误:

no such table: upload_uploadedfile

我做错了什么?我是django的初学者,发现文档相当不透明,所以我可能在做一些非常愚蠢的事情。

在创建上载文件模型后,您是否执行了django-admin.py syncdb


另一种方法是从项目文件夹中运行
python manage.py syncdb

在创建
上传文件
模型后,是否执行了
django-admin.py syncdb
?我忘了将我的模型添加到已安装的应用程序中。另外,我需要执行
managedb.py-syncdb
,而不是
django-admin.py-syncdb
。不过,谢谢你,你给我指明了正确的方向。