Hi i am trying to make blog website but while i fetch model with blogpost function in views.py its shows error that 404 page not found like ||Using the URLconf defined in mac.urls, Django tried these URL patterns, in this order: admin/ shop/ blog/ [name='BlogHome'] blog The current path, blog/blogpost, didn't match any of these. ||
-until i don't create model it works fine but after creating model and trying to fetch articles through post_id it throws error as page not found!
-what am i missing?
-Here is the codes i am using.
code of blog/urls.py ->
from django.urls import path
from . import views
urlpatterns = [
path(" ", views.index, name="ShopHome"),
path("blogpost/<int:id>/", views.blogpost, name="blogpost")]
code of blog/Views.py ->
from django.shortcuts import render
from .models import Blog
# Create your views here.
from django.http import HttpResponse
def index(request):
return render(request, 'blog/index.html')
def blogpost(request,id):
post= Blog.objects.filter (post_id=id)[0]
print(post)
return render(request, 'blog/blogpost.html',{'post':post})
code of blog/adminpy ->
from django.contrib import admin
from .models import Blog
admin.site.register(Blog)
code of blog/models.py ->
from django.db import models
# Create your models here.
class Blog(models.Model):
post_id = models.AutoField(primary_key= True)
title = models.CharField(max_length=50)
title0 = models.CharField(max_length=500,default='')
title1= models.CharField(max_length=500,default='')
title2= models.CharField(max_length=500,default='')
Content_title= models.CharField(max_length=500,default='')
Content_title0= models.CharField(max_length=500,default='')
Content_title1= models.CharField(max_length=500,default='')
Content_title2= models.CharField(max_length=500,default='')
pub_date = models.DateField()
image = models.ImageField(upload_to='shop/images', default="")
def __str__(self):
return self.title
question from:
https://stackoverflow.com/questions/65845223/page-not-found-404-request-method-get-the-current-path-blog-blogpost 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…