**views.py code**(views.py function id not call urls.py)
def SendMail(request,id):
post=get_object_or_404(Post,slug=slug,status='published')
form=EmailSendForm()
return render(request,'mail.html',{'form':form,'post':post})
**models.py**(models.py not accept the id number in views.py)
from django.contrib.auth.models import User
from django.db import models
from django.urls import reverse
from django.utils import timezone
类 CustomManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(status='published')
class Post(models.Model):
STATUS_CHOICES=(('draft','Draft'),('published','Published'))
id=models.IntegerField(primary_key=True)
title=models.CharField(max_length=300)
slug=models.SlugField(max_length=300,unique_for_date='publish')
author=models.ForeignKey(User,related_name='post',on_delete=models.CASCADE)
body=models.TextField()
publish=models.DateTimeField(default=timezone.now)
created=models.DateTimeField(auto_now_add=True)
updated=models.DateTimeField(auto_now=True)
status=models.CharField(max_length=10,choices=STATUS_CHOICES,default='draft')
objects=CustomManager()
class Meta:
ordering=('-publish', )
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post',args=[self.publish.year,
self.publish.strftime('%m'),
self.publish.strftime('%d'),
self.slug])
urls.py (urls show page not found 404 error) path('/(?P\d+)share/$',views.SendMail),