Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: AttributeError: module 'User.views' has no attribute 'User'

I have a few apps within my Django project and all of them seem to be working, except for the User app. All the apps are installed in the settings. Whenever I type "python manage.py runserver", I see a long line of code that ends with this:

File "/Users/Name/Desktop/Project_Name/MyProject/User/urls.py", line 5,                  
in <module>
url(r'Home/', views.User, name='Home'),
AttributeError: module 'User.views' has no attribute 'User'

MyProject/urls.py

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

        urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^$', include('Home.urls')),
        url(r'^Application', include('Application.urls')),
        url(r'^Login', include('Login.urls')),
        url(r'^User', include('User.urls')),
    ]

User/urls.py

    from django.conf.urls import url, include
    from User import views

    urlpatterns = [
        url(r'Home/', views.User, name='Home'),
        url(r'Matrices/', views.User, name='Matrices'),
    ]

User/views.py

    from django.shortcuts import render

    def Home(request):
        return render(request, 'Home.html')

    def Matrices(request):
        return render(request, 'Matrices.html')

If I remove "url(r'^User', include('User.urls'))" from MyProjects/urls.py, everything is working fine (but of course I cannot access the urls from User app). All the other apps have only one "url" and only User app has multiple urls. Is that where the issue lies?

Would greatly appreciate any help. Thanks!

like image 946
AyupovSukhrab Avatar asked Oct 18 '22 07:10

AyupovSukhrab


2 Answers

user/views.py has no method User, you have only two methods HOME and MATRICES, and you are trying to call a method named User doing this `

url(r'Matrices/', views.User, name='Matrices')

To solve your problem you need call an available method from user/views.py HOME or MATRICES like this

url(r'ThisIsTheNameOfTheUrlNotTheMethod/', views.Home, name='Home'),

or

url(r'matrices/', views.Matrices, name='Matrices'),
like image 134
Christian Buendia Avatar answered Oct 21 '22 00:10

Christian Buendia


Your urlpatterns needs to use the views.py functions like

urlpatterns = [
        url(r'Home/$', views.Home, name='Home'),
        url(r'Matrices/$', views.Matrices, name='Matrices'),
    ]
like image 32
Seixas Avatar answered Oct 20 '22 23:10

Seixas