0

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))
0

1 Answer 1

2

Change

def post(request, id):
    return HttpResponse("Hello this is post %" %(post_id))

to

def post(request, id):
    return HttpResponse("Hello this is post %s" % id)

And I suspect it will work a bit better!

Sign up to request clarification or add additional context in comments.

2 Comments

Ah yes, I had it as "id" before, however I have been missing the s from %s that part, thank you.
Looks like you forgot the %s on the end? In your original you forgot it, so maybe you didn't change it when you tried the above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.