Ich versuche, eine der statischen Seiten dazu zu bringen angezeigt, aber es tritt immer wieder ein 404-Fehler mit folgendem Inhalt auf (Hinweis: Ich habe den Namen der Anwendung durch „“ ersetzt):
Code: Select all
No article found matching the query
Request Method: GET
Request URL: http://127.0.0.1:8000/illustrations
Raised by: .views.ArticleDetailView
Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:
admin
[name='home']
[name='article_detail']
The current path, illustrations, matched the last one.
Ich kann nicht sagen, ob ich sollte die Homepage zu einer separaten App machen oder wenn ich nur meine URLs/Ansichtsdateien ändern muss. (Ich lerne Django und Python, also lerne ich definitiv im Laufe der Zeit.)
Hier ist views.py:
Code: Select all
from django.shortcuts import render
from django.views import generic
from .models import Article
from django.http import JsonResponse # Ignore for now, I just put this here for when I work on making a JSON feed
class ArticleListView(generic.ListView):
model = Article
paginate_by = 6
template_name = "index.html"
class ArticleDetailView(generic.DetailView):
model = Article
template_name = "article.html"
def illustrations(request):
return render(request, "illustrations.html")
Code: Select all
from django.contrib import admin
from django.conf import settings
from django.urls import path, include
from django.conf.urls.static import static
urlpatterns = [
path('admin', admin.site.urls),
path("", include(".urls")),
]
if settings.DEBUG: # new
urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Code: Select all
from django.urls import path
from . import views
from django.conf.urls.static import static # Not sure if needed
from django.views.generic import TemplateView
from .views import ArticleListView, ArticleDetailView
# For setup info, see https://learndjango.com/tutorials/django-file-and-image-uploads-tutorial
urlpatterns = [
path("", ArticleListView.as_view(), name="home"), # This is index.html,
path("", ArticleDetailView.as_view(), name="article_detail"),
path("illustrations", views.illustrations, name="illustrations"),
]