Manikanta
Manikanta

Reputation: 335

TypeError: __init__() takes 1 positional argument but 2 were given django

this is the urls.py

from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^/', include('main.urls', namespace='Home')),

]

this is the views.py

from django.shortcuts import render,HttpResponse,render_to_response,HttpResponseRedirect
from django.views.generic import TemplateView
from main.models import *

class leaflet(TemplateView):
    template_name = "file.html"

When I wrote this code template not showing, it throws an error:

__init__() takes 1 positional argument but 2 were given"

could you find the error in my code?

Upvotes: 1

Views: 2168

Answers (2)

Ramiro Uvalle
Ramiro Uvalle

Reputation: 241

You need to add leaflet.as_view() in urlpatterns

urls.py

from django.conf.urls import include, url
from django.contrib import admin
from main.views import leaflet

urlpatterns = [
   url(r'^admin/', include(admin.site.urls)),
   url(r'^/', include('main.urls', namespace='Home')),
   url(r'^test/', leaflet.as_view()),
]

Upvotes: 4

SHIVAM JINDAL
SHIVAM JINDAL

Reputation: 2974

You urls.py should be look like

from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^/', include('main.urls'), name='Home'),

]

Updated: If you are using django-version 1.8 or earlier, you should add app_name argument in include function

url(r'^/', include('main.urls', namespace='Home', app_name='polls'))

Upvotes: -1

Related Questions