DetailView Django dont work error page not found - django

When I click on the article I get
How can I fix it?
I tried url, path and other but I have this error
urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('index', include('mainpage.urls')),
path('blog', include('news.urls')),
path('games', include('games.urls')),
path('fortnite', include('fortnite.urls')),
path('contacts', include('contact.urls')),
path('admin', admin.site.urls),
]
news/urls.py
from django.urls import path,include,re_path
from django.conf.urls import url
from . import views
from django.views.generic import ListView, DetailView
from news.models import Articles
urlpatterns = [
path('', ListView.as_view(queryset=Articles.objects.all().order_by('-date')[:20],template_name='news.html')),
path('<int:pk>/', DetailView.as_view(model=Articles, template_name='news/post.html'))
]

First of all please add '/' at end of all your path strings , change it like this
path('index/', include('mainpage.urls')),
path('blog/', include('news.urls')),
path('games/', include('games.urls')),
path('fortnite/', include('fortnite.urls')),
path('contacts/', include('contact.urls')),
path('admin/', admin.site.urls),
]
check if it works or not

Related

I am currently using django 4.0 getting this error while including ('rest_auth.urls')

from django.contrib import admin
from django.urls import path,include
from Users.urls import *
from django.contrib import admin
urlpatterns = [
path('admin/', admin.site.urls),
path("",include("Users.urls")),
path('api/v1/rest-auth/', include('rest_auth.urls')),
]
Error:-ImportError: cannot import name 'url' from 'django.conf.urls'
In rest_auth.urls do this:
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
app_name = 'recipe'
urlpatterns = [
path('',include(router.urls)),
]
Hope your problem will solve now.

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

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.

urls.py django 2.0.2 need parameters

i'm learning django and i'm making a blog tutorial but it's from older version that i have, i have version 2.0.2 and i'm not understand documentation my problem is that i dont know how configure my urls.py
this is my three proyect:
i need to put archive.html in 127.0.0.1:8000/ and this is my urls code
codigofacilito/blog.urls.py :
"""codigofacilito URL Configuration
The urlpatterns list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin<br/>
from django.urls import path<br/>
from . import views<br/>
urlpatterns = [
path('admin/', admin.site.urls),
]
and codigofacilito/codigofacilito.urls.py:
from django.contrib import admin
from django.urls import path
from . import views
enter code here`urlpatterns = [
path('admin/', admin.site.urls),
]
from django.views.generic import TemplateView
urlpatterns = [
path('', TemplateView.as_view(template_name = 'archive.html')),
path('admin/', admin.site.urls),
]
put this in your project's urls.py, this will directly render the archive.html when you visit 127.0.0.1:8000/ in your browser.
but if you want to render data from backend in this html page then i suggest you to use views (function based , class based, etc..)
then you just have to import the views in url file and specify path for that.
from your_app.views import your_view
urlpatterns = [
path('/', your_view),
]

Reach main urls.py and use another app url

I have use 2 apps in my project named post and gallery. In url localhost:8000/en, I am using post.urls specifically "homepage". In homepage, when I want go to {% url "gallery:gallery_detail" "photos" %} it gives me an error. Because even though it takes a keyword "photos" it can not find any pattern specifically "gallery_detail".
My question is how can I reach this anathor app's url ?
My main urls.py:
from django.conf.urls import url,include
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^ckeditor/', include("ckeditor_uploader.urls")),
]
urlpatterns += i18n_patterns(
url(r'^gallery/', include("gallery.urls",namespace="gallery")),
url(r'^', include("post.urls", namespace="post")),
)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
My post.urls:
from django.conf.urls import url
from post.views import HomePageDetailView, AboutDetailView, \
CategoryDetailView, SponsorshipDetailView, CommonDetailView, NewsEntryDetailView
urlpatterns = [
url(r'^$', HomePageDetailView.as_view(), name="homepage"),
url(r'^about/(?P<slug>[-_\w]+)/$', AboutDetailView.as_view(),
name="about_detail"),
url(r'^category/(?P<slug>[-_\w]+)/$', CategoryDetailView.as_view(),
name="category_detail"),
url(r'^sponsorship/(?P<slug>[-_\w]+)/$', SponsorshipDetailView.as_view(),
name="sponsorship_detail"),
url(r'^news/(?P<slug>[-_\w]+)/$', NewsEntryDetailView.as_view(),
name="news_detail"),
url(r'^(?P<slug>[-_\w]+)/$', CommonDetailView.as_view(),
name="common_detail"),
]
My gallery.urls:
from django.conf.urls import url
from gallery.views import GalleryDetailView
urlpatterns = [
url(r'^(?P<slug>[-_\w]+)/$', GalleryDetailView.as_view(),
name="galery_detail"),
]