[Answer]-Exception Value: blog() takes exactly 2 arguments (1 given)

1👍

Change

url(r'$', blog),

To

url(r'$', 'views.blog_index', name='index'),

Or write a separate view.

The reason you’re getting your error, is because you’re attempting to execute the blog function which expects a slug from your title page. What you’re wanting to do is show the index from your title page which does not take a slug.

Also, the following is going to cause you pain:

from blog.views import blog_index, blog
from views import blog_index

Which blog_index do you want to be using? You’re better off using 'views.blog_index' notation in your URLs. Delete those imports above, and only use string based view names in your URLs like you’ve done for blog/ and blog_index/.

Edit: this is what your entire URLs should show (to get this working..)

import authority
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.defaults import url, include, patterns
from django.contrib import admin

admin.autodiscover()
authority.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    (r'^authority/', include('authority.urls')),
    (r'^i18n/', include('django.conf.urls.i18n')),
    (r'^admin/', include(admin.site.urls)),

    url(r'^$', 'views.blog', name='index'),
    url(r'^blog/(?P<slug>[-\w]+)/$', 'blog.views.blog', name="blog"),
    url(r'^blog/$', 'blog.views.blog_index', name="blog_index"),
)

if settings.DEBUG:
    urlpatterns += patterns('',
        # Trick for Django to support static files (security hole: only for Dev environement! remove this on Prod!!!)
        url(r'^admin/pages/page(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.PAGES_MEDIA_ROOT}),
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
        url(r'^admin_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.ADMIN_MEDIA_ROOT}),
    )

urlpatterns += patterns('',      
    (r'^', include('pages.urls')),
    )

Leave a comment