Repsol62
@Repsol62
Работаю пытаюсь изучить для работы языки программ

Укажите где ошибка not found 404?

Помогите пожалуйста разобраться где я допустил ошибку?
Page not found (404)
Request Method:	GET
Request URL:	http://127.0.0.1:8000/detail/9
Using the URLconf defined in iswork.urls, Django tried these URL patterns, in this order:

[name='home']
detail/ [name='detail_page']
edit-page [name='edit_page']
update-page/ [name='update_page']
delete-page/ [name='delete_page']
admin/
The current path, detail/9, didn't match any of these


urls.py

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('', include('core.urls')),
    path('admin/', admin.site.urls),
]


core/urls.py

from django.contrib import admin
from django.urls import path
from core import views

urlpatterns = [
    path('', views.HomeListView.as_view(), name='home'),
    path('detail/', views.HomeDetailView.as_view(), name='detail_page'),
    path('edit-page', views.edit_page, name='edit_page'),
    path('update-page/', views.update_page, name='update_page'),
    path('delete-page/', views.delete_page, name='delete_page'),

]


core/views

from django.shortcuts import render,redirect

from .models import Articles
from django.views.generic import ListView, DetailView
from .forms import ArticleForm
from django.urls import reverse


class HomeListView(ListView):
    model = Articles
    template_name = 'index.html'
    context_object_name = 'list_articles'


class HomeDetailView(DetailView):
    model = Articles
    template_name = 'detail.html'
    context_object_name = 'get_article'

def edit_page(request):
    success = False
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            success = True
 
    template = 'edit_page.html'
    context = {
        'list_articles': Articles.objects.all().order_by('-id'),
        'form':ArticleForm(),
        'success':success
    }
    return render(request,template,context)
 
 
def update_page(request,pk):
    success_update = False
    get_article = Articles.objects.get(pk=pk)
    if request.method == 'POST':
        form = ArticleForm(request.POST,instance = get_article)
        if form.is_valid():
            form.save()
            success_update = True
            template = 'edit_page.html'
            context = {
                'get_article': get_article,
                'update':True,
                'form':ArticleForm(instance = get_article),
                'success_update':success_update
    }
    return render(request, template, context)
 

def delete_page(request,pk):
    get_article = Articles.objects.get(pk=pk)
    get_article.delete()
    
    return redirect(reverse('edit_page'))
  • Вопрос задан
  • 1997 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы