hey i have a url path that i want to lead me to an application url file
but it says page not found
here is my core url:
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')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
and here is my basket.url file:
from django.urls import path
from . import views
app_name = 'basket'
urlpatterns = [
path('', views.basket_summary, name='basket_summary'),
]
and this is the view:
from django.shortcuts import render
# Create your views here.
def basket_summary(request):
return render(request, 'store/basket/summary.html')
my app name is basket , and i might add all of the files are defined.
whats the problem ?
You should add a trailing slash after /basket/.
Read more about APPEND_SLASH in the official documentation.
Related
When using the URL template tag I checked the source code of the html page and the url appears missing the last letter of the base address, see an example:
...
<li>Products</li>
...
returns
...
<li>Products</li>
...
but the the base address is my-site.com/deck
...
so, why dont returns
...
<li>Products</li>
...
I checked my settings.py and urls.py and didn't see anything wrong, I don't know where else to look
my urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path, re_path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('principal.urls')),
path('product/', include('products.urls'), name='product'),
] + static(settings.MEDIA_URL, document_root=settings.STATIC_ROOT)
and the urls.py from app product
from django.urls import path
from . import views
urlpatterns = [
path('', views.ProductHTMxTableView.as_view(), name='products'),
path('product/<int:pk>', views.ProductDetail.as_view(), name='product_detail'),
path('show/', views.ProductShow.as_view(), name='product_show'),
]
I have a weird problem with django not finding my file. Should be basic, but I cannot figure that out. If my app name is convers and the the file convers/urls.py (same folder as where settings.py is) reads:
form django.contrib import admin
from django.urls import path,include
from django.views.generic import RedirectView
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('c/',include('convers_app.urls')),
path('conversapp/',include('convers_app.urls')),
path('',RedirectView.as_view(url='conversapp/')),
] + static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
the urls.py in my convers_app folder reads
from django.urls import path
from .import views
urlpatterns = [
path('',views.index, name='index'),
path('timer', views.timer, name='timer')
]
and in my views.py folder I have
def timer(request):
return render(request, 'timer.html')
I also have the timer.html in my templates folder.
What am I missing? Why won't django locate my timerview?
I am just learning Django. I can't understand why "index" is being added to the empty URL. I need the address to be http://127.0.0.1:8000/, but in the address bar it immediately changes to http://127.0.0.1:8000/index/.
However, if I enter http: // localhost: 8000 / there are no such problems.
urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from django.urls import include
from about import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('about.urls')),
path('ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
about app urls
from django.urls import path, re_path
from django.views.generic import RedirectView
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
The solution was very simple, it was necessary to clear the browser cache :)
I got the follwoing error whenever I run the project and automatically catalog/ is added to the url:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/catalog/
Using the URLconf defined in first_project.urls, Django tried these URL patterns, in this order:
[name='index']
admin/
first_app/
The current path, catalog/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Here is my project urls.py
from django.contrib import admin
from django.urls import path, include
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
path('first_app/', include('first_app.urls')),
]
Here is first_app urls.py code:
from django.urls import path
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
]
How to get the index page as a default and get rid of the catalog.
Here is views.py file:
from django.shortcuts import render
from django.http import HttpResponse
from first_app.models import Topic, AccessRecord, Webpage
# Create your views here.
def index(request):
webpages_list = AccessRecord.objects.order_by('date')
date_dict = {'access_records': webpages_list}
return render(request, 'first_app/index.html', context=date_dict)
Hey Mak in your code u didnt mention any url related to /catalog/ so you are getting that 404 error message. Error 404 means that the page couldnt found by the server add /catalog/ in your url patterns so that the server could know which page is to be shown if /catalog/ is requested . And as far as ur proble"and automatically catalog/ is added to the url:" may be its your browser autocompleting the address field so once plesase check it. if the request is only /catalog then ur myproject urls.py file should be something like this
from django.contrib import admin
from django.urls import path, include
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
path('admin/', admin.site.urls),
path('first_app/', include('first_app.urls')),
path('catalog',views.your_function_name)
]
if the request is first_app/catalog then ur first_app urls.py file should be something like this in url patterns
urlpatterns = [
path('/catalog', views.catalog, name='catalog'),
]
from django.contrib import admin
from django.urls import path, include
from first_app import views
urlpatterns = [
path('admin/', admin.site.urls),
path('first_app/', include('first_app.urls')),]
and
from django.urls import path
from first_app import views
urlpatterns = [
path('', views.index, name='index'),
]
>>>>> if your templates files :
templates/index.html
def index(request):
webpages_list = AccessRecord.objects.order_by('date')
date_dict = {'access_records': webpages_list}
return render(request, 'index.html', context=date_dict)
Everything works fine on development server but in production server I can only access views.home at https://www.host.com/ and everything else such as
https://www.host.com/b/ or https://www.host.com/tab or https://www.host.com/ext returns status_code 500.
I'm using django 2.1 in python 3.7. Cheers!
Here's the project level urls.py
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from ext.forms import CustomAuthForm
from mysite import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
path('login/', auth_views.LoginView.as_view(authentication_form = CustomAuthForm), name='login'),
path('logout/', auth_views.LogoutView.as_view(next_page= settings.LOGOUT_REDIRECT_URL), name='logout'),
path('', include('ext.urls')),
]
urlpatterns += staticfiles_urlpatterns()
And app level urls.py looks like this
from django.urls import path, re_path
from django.conf.urls import url
from ext import views
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
app_name = 'ext'
urlpatterns = [
path('', views.home, name='home'),
path('int/', views.get_int_status, name='home-load-int'),
path('ext/', views.get_ext_status, name='home-load-ext'),
path('tab/', views.get_tab_status, name='home-load-tab'),
path('b/', views.uzair, name='home-uzair'),
]
I was missing RewriteEngine On in my .httaccess file, what a shame xD