Phil H Phil H - 1 year ago 380
Python Question

url() got an unexpected keyword argument 'namespace'

New to Django here, so pardon the rookie question...

I'm getting the

url() got an unexpected keyword argument 'namespace'
error when I try to call on the
function. Tried a few different ways to fix it but nothing seems to be working. Any advice would be greatly appreciated. Please see my code below:

TypeError at /comments/topic-create/
url() got an unexpected keyword argument 'namespace'
Request Method: POST
Request URL:
Django Version: 1.8.6
Exception Type: TypeError
Exception Value:
url() got an unexpected keyword argument 'namespace'

from django.db import models
from django.conf import settings
from django.utils.text import slugify
from django.core.urlresolvers import reverse

class Topic(models.Model):
title = models.CharField(max_length=50)
stock = models.ManyToManyField(Stock)
slug = models.SlugField(max_length=200, blank=True)
created = models.DateField(auto_now_add=True,

def __str__(self):
return self.title

def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Topic, self).save(*args, **kwargs)

def get_absolute_url(self):
return reverse('comments:topic_detail', args=[, self.slug])

from django import forms
from .models import Topic

class TopicCreateForm(forms.ModelForm):
class Meta:
model = Topic
fields = ('__all__')

from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from .forms import TopicCreateForm
from django.contrib import messages
from .models import Stock, Topic, Comment
# from django.core.urlresolvers import reverse_lazy

def topic_create(request):
if request.method == 'POST':
form = TopicCreateForm(data=request.POST)
if form.is_valid():
cd = form.cleaned_data
new_item =
new_item.user = request.user
messages.success(request, 'Topic added successfully')
# redirect to new created topic detail view
return redirect(new_item.get_absolute_url())
form = TopicCreateForm(data=request.GET)

return render(request,
{'section': 'topic',
'form': form})

def topic_detail(request, namespace, id, slug):
topic = get_object_or_404(Topic, id=id, slug=slug)
return render(request,
{'section': 'topic',
'topic': topic})


from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^topic-create/$', views.topic_create, name='create-topic'),
views.topic_detail, name='topic-detail'),


from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(,
url(r'^account/', include('account.urls')),
url(r'^comments/', include('comments.urls'),

Answer Source

You can refer the syntax and options for the url include() method in official django documentation here. You need to use the namespace inside the include() method and not in the outside url() method.

url(r'^comments/', include('comments.urls', namespace='comments')),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download