Hello I am getting the following error in Django (latest version):
TypeError at /post/1/
post() got an unexpected keyword argument 'post_id'
This occurs when I press on a link on the home page to view the post it's self, I am trying to pass along the post's id (I am using the default [hidden] primary key, not my own custom one)
This is what my urls.py looks like for both the index and post page:
from django.conf.urls.defaults import patterns, include, url
from journal.models import Post
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('journal.views',
(r'^$', 'index'),
(r'^post/(?P<id>\d+)/$', 'post'),
Here is my views.py:
from django.http import HttpResponse
from journal.models import Post
from django.template import Context, loader
import os
# Hardcoded Varibles
SITE_ROOT = os.path.join(os.path.dirname(__file__))
# Create your views here.
def index(request):
latest_post_list = Post.objects.all().order_by('-pub_date')[:10]
t = loader.get_template(os.path.join(SITE_ROOT, 'templates', 'index.html'))
c = Context({
'latest_post_list': latest_post_list,
})
return HttpResponse(t.render(c))
def post(request, id):
return HttpResponse("Hello this is post %" %(post_id))