Reputation: 49
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!
Upvotes: 5
Views: 14985
Reputation: 438
Hey if someone else is facing this error and cant solve using solution of this question. You can solve using saving your views.py
of your app before running.
Upvotes: 0
Reputation: 512
in your User/urls.py
replace the following line:
from User import views
with the following line:
from . import views
Upvotes: 0
Reputation: 11
url(r'Home/', views.User, name='Home')
From the above code, try removing the space between the comma and the words views.user
. That fixed my problem.
Illustration: code should look like;
url(r'Home/',views.User, name='Home')
. no space between comma
and views.user
Upvotes: 0
Reputation: 56
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'),
Upvotes: 2
Reputation: 11
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'),
]
Upvotes: 1