2

I'm trying to implement the solution to error

ImproperlyConfigured
TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()

Here's my urls.py as suggested

from django.urls import include, path, re_path

urlpatterns = [
    re_path(r'^auth/registration/account-confirm-email/(?P<key>[\s\d\w().+-_',:&]+)/$', TemplateView.as_view(), name = 'account_confirm_email'),
    path('auth/registration/', include('dj_rest_auth.registration.urls')),
]

But I'm getting this error.

re_path(r'^registration/account-confirm-email/(?P<key>[\s\d\w().+-_',:&]+)/$', TemplateView.as_view(), name = 'account_confirm_email'),
                                                                     ^
SyntaxError: invalid syntax

Any idea on what I could be missing? Thanks!

1 Answer 1

3

The syntax highlighting already shows the problem, there is a quite in your regex that ends the regex prematurely. You can fix this using double quotes:

from django.urls import include, path, re_path

urlpatterns = [
    re_path(
        r"^registration/account-confirm-email/(?P<key>[\s\d\w().+-_',: & ]+)/$",
        TemplateView.as_view(),
        name='account_confirm_email'
    ),
    path('auth/registration/', include('dj_rest_auth.registration.urls')),
]

But this will not fix the first error. This is complaining about the fact that you did not pass a template_name parameter to the TemplateView:

urlpatterns = [
    re_path(
        r"^registration/account-confirm-email/(?P<key>[\s\d\w().+-_',: & ]+)/$",
        TemplateView.as_view(template_name='some_template.html'),
        name='account_confirm_email'
    ),
    path('auth/registration/', include('dj_rest_auth.registration.urls')),
]

As @HakenLid says, perhaps you can also simplify the regex to (?P<key>.+), this of course alters the semantics a bit.

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

1 Comment

They might also consider using a simpler regex pattern for the "key" group. I suspect (?P<key>.+) would probably work fine.

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.