Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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
Python 没有这样的专栏-Django_Python_Django - Fatal编程技术网

Python 没有这样的专栏-Django

Python 没有这样的专栏-Django,python,django,Python,Django,我的目标是让用户上传文件到用户特定的文件夹 我得到的错误是 no such column: notendur_document.user_id 下面是my views.py文件的相关部分。这就是上传发生的地方 @login_required def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.F

我的目标是让用户上传文件到用户特定的文件夹

我得到的错误是

no such column: notendur_document.user_id
下面是my views.py文件的相关部分。这就是上传发生的地方

@login_required
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('notendur.views.list'))
    else:
        form = DocumentForm() # An empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'notendur/list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )
这是我的models.py文件:

根据相关的.html文件,错误发生在列表中的documents变量中

在views.py中注册用户方法:


只需在foreingkey中传递pk=True ex.user=models.ForeignKeyUser,pk=True
这将解决问题

您更改了模型,但忘了迁移或djangoI中的syncdb可能还有另一个错误,但我得到了相同的错误。我只是关闭服务器,编写python manage.py syncdb,然后再次启动服务器。我做得对吗?删除数据库,再次创建,然后运行syndbIt仍然不起作用,但我有一个想法。我没有从shell创建用户。我让用户自己在网站上注册。我可能在那里做错了什么,导致了这个错误吗?也许创建的用户对象不正确?将来,当您已经有一些不想丢失的数据时,您可能希望更改模型。然后你必须手动修改你的表格,这很烦人。考虑使用Souple进行模式迁移或升级到Django 1.7,这是内置的。
def _upload_path(instance,filename):
    return instance.get_upload_path(filename)

class Document(models.Model):
    docfile = models.FileField(upload_to=_upload_path)
    user = models.ForeignKey(User)

    def get_upload_path(self,filename):
        return "media/uploads/"+str(self.user.id) + "/" + '%Y.%m.%d' + filename
def register_user(request):
    if request.method == "POST":
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts/register_success')

    args  = {}
    args.update(csrf(request))

    args['form'] = UserCreationForm()

    return render_to_response('register.html', args)