我想添加評論到我的項目,我有這個錯誤:feeds() missing 1 required positional argument: 'id'
。這是我的代碼。Django - 類型錯誤在飼料()缺少1需要的位置參數:'ID'
views.py
@login_required
def feeds(request, id):
feeds_list = Feed.objects.all()
feed = get_object_or_404(Feed, id=id)
users = User.objects.filter(is_active=True)
if request.method == 'POST':
# Komentarz został opublikowany.
feed_form = FeedForm(request.POST)
if feed_form.is_valid():
# Utworzenie obiektu Comment, ale jeszcze nie zapisujemy go w bazie danych.
new_feed = feed_form.save(commit=False)
new_feed.user = request.user
new_feed.date = timezone.now
# Zapisanie komentarza w bazie danych.
new_feed.save()
else:
feed_form = FeedForm()
context = {'section': feeds,
'users': users,
'feeds_list': feeds_list,
'feed_form': feed_form}
return render(request, 'feed/list.html', context)
我認爲這是這裏的問題:feed = get_object_or_404(Feed, id=id)
,但我不知道如何解決它。
感謝您的幫助。
編輯: urls.py
from django.contrib.auth.urls import url
from . import views
app_name = 'feedApp'
urlpatterns = [
url(r'^$', views.feeds, name='feeds'),
url(r'^feed/new$', views.post_new, name='post_new'),
url(r'^feed/(?P<id>[0-9]+)/$', views.feed, name='post_detail'),
# url(r'^feed/(?P<id>[0-9]+)/comment$',
# views.comment_feed,
# name='comment_feed'),
url(r'^feed/(?P<id>[0-9]+)/delete/$',
views.feed_delete,
name='feed_delete'),
]
貼'urls.py' –
feeds'預計,鑑於''id'存在於網址。您的端點應該是這樣的 - localhost:8000/ –
如果在完全錯誤跟蹤後發生錯誤 – badiya