AttributeError: module 'calc.views' has no attribute 'home' - django

I know there are some questions asked already but none of worked for me
server is not running with the command throwing this error
calc urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home, name='home')
]
calc views.py
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello World !")
saish urls.py
from django.contrib import admin
from django.urls import path , include
urlpatterns = [
path('', include('calc.urls')),
path('admin/', admin.site.urls),
]

Related

Why am I getting error 404 in my django project when everything seems correct?

I have two apps in my Django project:basket and store. In root url files I configured the urls.py like this:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls', namespace='store')),
path('basket/', include('basket.urls', namespace='basket')),
store/urls.py:
from django.urls import path
from . import views
app_name = 'store'
urlpatterns = [
path('', views.all_products, name='all_products'),
path('<slug:slug>/', views.product_detail, name='product_detail'),
path('category/<slug:category_slug>/',
views.category_list, name='category_list')
]
basket/urls.py:
from django.urls import path
from . import views
app_name = 'basket'
urlpatterns = [
path('', views.basket_summary, name='basket_summary'),
path('add/', views.basket_add, name='basket_add'),
]
I am getting an error:
Page not found(404)
Request Method:GET
Request URL:http://127.0.0.1:8000/basket/
Raised by:store.views.product_detail
this is my store/views.py:
from django.shortcuts import get_object_or_404, render
from .models import *
def product_detail(request, slug):
product = get_object_or_404(Product, slug=slug, in_stock=True)
context = {
'product': product,
}
return render(request, 'store/products/detail.html', context)
please help me solve this problem i've been stuck on this for a long time.
Try this way if you want to avoid 404 error:
from django.shortcuts import get_object_or_404, render
from .models import *
def product_detail(request, slug):
try:
product = Product.objects.get(slug=slug, in_stock=True)
context = {
'product': product,
}
except Product.DoesNotExist:
raise ValidationError('Product Does not exist ')
return render(request, 'store/products/detail.html', context
)

does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import .Django 3.0.2

Project name : CRMPROJECT
App name: leads
I'm working on a CRM project With Django and I keep getting this error while trying to map my urls to views
django.core.exceptions.ImproperlyConfigured. The included URLconf does not appear to have any patterns in it
Below is the project/urls.py file
'''
from django.contrib import admin
from django.urls import path,include
from leads import views
urlpatterns = [
path('admin/', admin.site.urls),
path('leads/',include('leads.urls',namespace='leads')),
]
'''
Below is leads/urls.py
from django.urls import path
from . import views
app_name = 'leads'
urlpatterns = [
path('',views.home,name='home'),
]
And lastly my leads/views.py
'''
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home(request):
return render(request,'leads/base.html')
'''

I'm unable to run server due to this error: 'urls.py'>' does not appear to have any pattern'"

Error:
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'dtapp.urls' from 'D:\\pylearn\\dt\\dtapp\\urls.py'>p.urls' from D:\\pylearn\\dt\\dtapp\\ then the issue is probably caused by a circterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.news),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
def news(request):
return HttpResponse ("n iuri u iou")
urls.py(django)
from django.contrib import admin
from django.conf.urls import url,include
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^dtapp/', include('dtapp.urls'))
]

App error . Attribute error with first application

I have created this app in django but i cannot access the app . CMD says
Attribute error : module 'hello.views' has no attribute 'index'
VIEWS.PY
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello World !!!')
URLS.PY/admin
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('hello.urls'))
]
URLS.PY/Hello
from django.urls import path
from . import views
urlpatterns = [
path('hello/', views.index, name='index')
]
You need to put commas after path().
path('hello/', views.index, name='index'), # Very important comma.
I think you missed one in each file.
I now see the other problem. Change your hello.urls.py path to
path('',
Your current configuration is looking for
/hello/hello/
If you put that in your browser it might work.

NoReverseMatch at /new_application/check_login/

I am new to DJango. I am getting error 'NoReverseMatch at /new_application/check_login/' while redirecting view from another view.
different files listed below.
Main urls.py
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^new_application/', include('new_application.urls')),
]
views.py
from django.shortcuts import render, render_to_response
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from .models import Login
...
def check_login(request):
...
return HttpResponseRedirect(reverse('new_application:loggedin',args=(user,)))
def loggedin(request, user):
return render(request, 'new_application/loggedin.html',{'full_name': user.first_name +" "+ user.last_name})
Application urls.py
from django.conf.urls import url
from . import views
app_name = 'new_application'
urlpatterns = [
url(r'^$', views.login, name='login'),
url(r'^check_login/$', views.check_login, name='check_login'),
url(r'^loggedin/$', views.loggedin, name='loggedin'),
url(r'^invalid_login/$', views.invalid_login, name='invalid_login'),
url(r'^logout/$', views.logout, name='logout'),
]
Here is an error image : error image
please give the solution for fixing this error.
Thank You.
The regex pattern must match against the given url...
url(r'^loggedin/(?P<user>\w+)/$', views.loggedin, name='loggedin'),
Reverse should match one of URL names from urls.py
return HttpResponseRedirect(reverse('loggedin',args=(user,)))