django, cannot access 2nd app (new dir) index page - django

I am hitting a conflict with a prior configuration and not sure how to get around the error.
error:
Exception Value: module 'userarea.views' has no attribute 'home_view'
from project urls.py:
$ cat exchange/urls.py
from django.contrib import admin
from django.urls import path, include
from pages.views import home_view, contact_view, about_view, user_view
#from products.views import product_detail_view
from userdash.views import userdash_detail_view, userdash_create_view
from django.conf.urls import include
from django.urls import path
from register import views as v
from pages import views
from userarea import views
urlpatterns = [
path('', views.home_view, name='home'),
path('', include("django.contrib.auth.urls")),
path('admin/', admin.site.urls),
path("register/", v.register, name="register"),
path('userdash/', userdash_detail_view),
path('contact/', contact_view),
path('', include("userarea.urls")),
path('create/', userdash_create_view),
path('about/', about_view),
path('user/', user_view),
]
I either get this error or problem with it trying to access my default.
But unable to find a work around.
from app views.py
$ cat userarea/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def uindex(response):
return HttpResponse("<h1>New user dashboard area</h1>")
app urls.py:
$ cat userarea/urls.py
from django.urls import path
from . import views
urlpatterns = [
path("uindex/", views.uindex, name="user index"),
]
How do I get my new/2nd project to not conflict with my previous app and load it's own index page in it's directory?
full debug error:
AttributeError at /uindex
module 'userarea.views' has no attribute 'home_view'
Request Method: GET
Request URL: http://192.168.42.13:8080/uindex
Django Version: 2.2.7
Exception Type: AttributeError
Exception Value:
module 'userarea.views' has no attribute 'home_view'
Exception Location: ./exchange/urls.py in <module>, line 28
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.7.3
Python Path:
['.',
'',
'/home/kermit/Env/secret/lib/python37.zip',
'/home/kermit/Env/secret/lib/python3.7',
'/home/kermit/Env/secret/lib/python3.7/lib-dynload',
'/usr/lib/python3.7',
'/home/kermit/Env/secret/lib/python3.7/site-packages']
Note updated urlpatterns twice and errors
new update:
This is what it appears to be calling, but I can't figure out how to differentiate between the two calls.
$ cat pages/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home_view(request, *args, **kwargs):
return render(request, "home.html",{})
def contact_view(request, *args, **kwargs):
return render(request, "contact.html",{})
def about_view(*args, **kwargs):
return HttpResponse('<h1>About Page</h1>')
def user_view(request, *args, **kwargs):
my_context = {
"my_text": "This is my context",
"my_number": "123",
"my_list": [1121, 1212, 3423, "abc"]
}
print(args, kwargs)
print(request.user)
return render(request, "user.html", my_context)
Big UPDATE (changes made above also):
I create a brand spanking new project and used the exact same configuration and it works find.
(Env) piggy#tuna:~/www/src/exchange2 $ cat userdash/urls.py
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path("userdash/", views.userdash, name="user dash"),
]
(Env) piggy#tuna:~/www/src/exchange2 $ cat exchange2/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("userdash.urls")),
]
(Env) piggy#tuna:~/www/src/exchange2 $ cat userdash/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(response):
return HttpResponse("<h1>Hello World!</h1>")
def userdash(response):
return HttpResponse("<h1>User Dashboard!</h1>")
why does my include() method of creating directories want to conflict with a standard path()?

from
irc.freenode.net #django user <GinFuyou>
.
from userarea import views as userarea_views
the key was
userarea_views

Related

onw of my two app is not working in django

Below is my code. In my hello_world project there is two app pages. one is home page and another is profile page. home page is working fine, but profile page is showing error.
hello_world urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('home_page.urls',)),
path('profile_page',include('profile_page.urls',))
]
home page urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.home,name='home page'),
]
home page views.py
from django.http import HttpResponse
def home(request):
return HttpResponse('home page')
profile page urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('profile_page',views.profile,name='profile page'),
]
profile page views.py
from django.http import HttpResponse
def profile(request):
return HttpResponse('profile page')
You need to use redirect method and include view name space as an argument..
Find the updated code:
from django.http import HttpResponse
def profile(request):
return redirect('profile page')
Don't forgot to import redirect...
The first argument of the path() function, i.e. the 'route' argument, must end with a forward slash.
path('profile_page/',include('profile_page.urls',))
Notice the forward slash at the end of the first argument, 'profile_page/'.
Your URLconf is not matching the expected pattern because of the missing slash.

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')
'''

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

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),
]

How to fix 'The included URLconf 'gp.urls' does not appear to have any patterns in it'

when i tried to write the first urlpattern and the first view, i got this error, so i can be able to access to the authentification template, i have no idea what can be the source of this error
# my gp/urls.py
from django.contrib import admin
from django.conf.urls import url
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$', views.index, name='index'),
]
# my views.py
from django.shortcuts import render
def index(request):
return render(request,'gp/index.html')
when i try to run the server this is the error i get
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf
'gp.urls' 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.
this is my program tree
gp
apps
conge
organisation
personnel
stage
gp
pycache
init.py
settings.py
urls.py
views.py
wsgi.py
static
templates
gp
index.html
db.sqlte3
manage.py
# my gp/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name='index'),
]
# my views.py
from django.shortcuts import render
def index(request):
return render(request,'gp/index.html', {})
what i edited is:
instead of from django.conf.urls import url i wrote from
django.urls import path
added {} in render function (its optional but just in case :) )
As stated in here: https://code.djangoproject.com/ticket/30728#no1
Maybe try to use latest Python version. Python 3.9 able to work