bne bne - 1 year ago 87
Python Question

attributeerror: 'module' object has no attribute 'register_success'

I had a project with log application . I removed it and have done a registration application in order to integrate Database and if you are not signed up you can't sign in ..... But When I runserver my Django project . I obtain an attribute error in reg application but I didn't known how to solve it .


from django.conf.urls import url

from . import views

urlpatterns = [
url(r'^$', views.login, name='login'),
url(r'^$', views.auth_view, name='auth_view'),
url(r'^$', views.loggedin, name='loggedin'),
url(r'^$', views.invalid_login, name='invalid_login'),
url(r'^$', views.register_user, name='register_user'),
url(r'^$', views.logout, name='logout'),
url(r'^$', views.register_success, name='register_success'),



from django.shortcuts import render
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf
def login(request):
c = {}
return render_to_response('login.html', c)

def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticated(username=username, password=password)

if user is not None:
auth.login(request, user)
return HttpResponseRedirect('loggedin')
return HttpResponseRedirect('invalid')

def loggedin(request):
return render_to_response('loggedin.html',
{'full_name': request.user.username})
def invalid_login(request):
return render_to_response('invalid_login.html')
def logout(request):
return render_to_response('logout.html')
def register_user(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('register_success')

args = {}

args['form'] = UserCreationForm()

return render_to_response('register.html', args)
def register_success(request):
return render_to_response('register_success.html')


from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.auth import views
from log.forms import LoginForm

urlpatterns = [
url(r'^aps/', include('aps.urls')),
url(r'^mail/', include('mail.urls')),
url(r'^reg/', include('reg.urls')),
url(r'^reg/register_success/$', views.register_success),
url(r'^reg/register/$', views.register_user),
url(r'^reg/invalid/$', views.invalid_login),
url(r'^reg/loggedin/$', views.loggedin),
url(r'reg/login/$', views.login),
url(r'reg/logout/$', views.logout),
url(r'reg/auth/$', views.auth_view),


Answer Source

You don't need to add all urls under reg/ individually into site/ as url(r'^reg/', include('reg.urls')) already does that automatically for you.

Here is the corrected version of urlpatterns defined in sites/

from django.conf.urls import patterns

urlpatterns = patterns(
    (r'^aps/', include('aps.urls'),
    (r'^mail/', include('mail.urls'),
    (r'^reg/', include('reg.urls'),

and reg/

from django.conf.urls import patterns

urlpatterns = patterns(
    url(r'^login/$', views.login, name='login'),
    url(r'^auth/$', views.auth_view, name='auth_view'),
    url(r'^loggedin/$', views.loggedin, name='loggedin'),
    url(r'^invalid/$', views.invalid_login, name='invalid_login'),
    url(r'^register/$', views.register_user, name='register_user'),
    url(r'^logout/$', views.logout, name='logout'),
    url(r'^register_success/$', views.register_success, name='register_success'),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download