I am attempting to add a blog to an existing test website, but I am receiving the following error message:
blog() missing 1 required positional argument: 'blog_id'
This may be a simple mistake I have made, but I am stumped at what I have done incorrectly and how to fix this. I have searched google and SO, but I haven't found a suitable reference.
Here is my models class:
class Blog(models.Model):
blog_title = models.CharField(null=False, blank=False, max_length=150, unique=True)
blog_description = models.CharField(null=False, blank=False, max_length=500)
blog_script = models.CharField(null=True, blank=True, max_length=5000)
blog_date_released = models.DateField(null=False, blank=False)
blog_tags = models.CharField(null=True, blank=True, max_length=150)
blog_video_url = models.URLField(null=False, blank=False, max_length=250)
blog_timestamp_added = models.DateTimeField(auto_now_add=True, auto_now=False)
blog_timestamp_updated = models.DateTimeField(auto_now=True, auto_now_add=False)
Here is my views.py file:
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from myapp.core.decorators import *
from myapp.core.models import Blog
def blog(request, blog_id):
blog = Blog.objects.get(pk=blog_id)
....
return render(request, 'blog/blog.html', {
'blog': blog,
'display_default_language': the_display_default_language,
'language_versions': language_versions,
'language_versions_num_enabled': language_versions_num_enabled,
'language_versions_num_total': language_versions_num_total,
'var_page_title': _("Blog"),
})
Here is mu urls.py file:
urlpatterns = [
....
url(r'^blog/blog/$', views.blog, name='blog'),
]
Any help will be greatly appreciated.
答案 0 :(得分:2)
您需要从您的网址传递blog_id
:
from . import views
url(r'^blog/(?P<blog_id>\d+)/$',views.blog, name='blogs'),