S
S
Sergey Nizhny Novgorod2016-02-17 10:01:54
Django
Sergey Nizhny Novgorod, 2016-02-17 10:01:54

How to fix ViewDoesNotExist error in Django?

Django 1.9.2
Error:
ViewDoesNotExist at /auth/registration/
Could not import 'loginsys.views.registration'. View does not exist in module loginsys.views.
____________________
Main file url.py

from django.conf.urls import include, url
from django.contrib import admin
from bakot import urls as bakot_urls
from loginsys import urls as loginsys_urls

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include(bakot_urls)),
    url(r'^auth/', include(loginsys_urls)),
]

loginsys.urls.py file
from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from loginsys import views

urlpatterns = [
    url(r'^login/', views.login, name='login'),
    url(r'^logout/', views.logout, name='logout'),
    url(r'^registration/', views.registration, name='registration'),
    url('^', include('django.contrib.auth.urls'))
]

View:
loginsys.views.py
from django.contrib import auth
from django.shortcuts import render, redirect, render_to_response
from django.template.context_processors import csrf
from django.contrib.auth.forms import UserCreationForm
from loginsys.models import UserCreationCustomForm

def registration(request):
    args = {}
    args.update(csrf(request))
    args['form'] = UserCreationCustomForm()
    if request.POST:
        newuser_form = UserCreationCustomForm(request.POST)
        if newuser_form.is_valid():
            newuser_form.save()
            newuser = auth.authenticate(username = newuser_form.cleaned_data['username'], password = newuser_form.cleaned_data['password2'])
            auth.login(request, newuser)
            return redirect('/step3')
        else:
            args['form'] = newuser_form
    return render_to_response('registration.html', args)

Everything works on the local machine, bakot.views.py (which is also included) also works.
On bourgeois forums, I found a couple of topics with ./manage.py shell and import handles, but something does not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanOne, 2016-02-17
@IvanOne

I'm not sure but it could be import views in loginsys.urls, just try import views

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question