我正在開發一個簡單的應用程序。我的應用程序允許用戶創建一個帳戶並添加電路板。Django all()得到了一個意想不到的關鍵字參數'user'
我試圖檢索用戶創建並顯示在模板上的所有板,而不會出現此錯誤。
all() got an unexpected keyword argument 'user'
Traceback:
File "C:\Python26\Lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\o\mysite\pet\views.py" in Display
69. board = Board.objects.all(user=request.user)
我的models.py
from django.db import models
from django.db.models.signals import post_save
from django.contrib.auth.models import User
class Person(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
image = models.FileField(upload_to="images/",blank=True,null=True)
def __unicode__(self):
return self.name
class Board(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
我views.py的部分(問題是在這裏)
def Display(request):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('pet.views.LoginRequest'))
board = Board.objects.all(user=request.user)
return render(request,'edit.html',{'board':board})
我edit.html
{% if board %}
<ul>
<li>Name: {{ board.name }}</li>
</ul>
{% endif %}
你現在的看法很好。很高興看到排列簡單的代碼 – catherine 2013-03-09 15:34:10
我之前嘗試過您的答案,但它不顯示所有主板 – donkeyboy72 2013-03-09 15:35:03
您有有用戶的主板上的數據嗎? – catherine 2013-03-09 15:39:22