【发布时间】:2021-08-18 19:38:30
【问题描述】:
我正在尝试生成不同的页面,但是当我单击时只出现实际页面,而不是加载了值的页面。 但是当我在 url 中手动添加 uid 时,页面就会出现。
这是我的看法,这两个是相关的,
def link_view(request, uid):
results = AffProduct.objects.get(uid=uid)
return render(request, 'link.html', {"results":results})
def link(request):
return render(request, 'link.html')
这是我的网址格式,
path('link/', views.link, name='link'),
path('link/<int:uid>', views.link_view, name='link_view'),
这是模型,
class AffProduct(models.Model):
user=models.ForeignKey(User, on_delete=models.CASCADE)
product_title = models.CharField(max_length=255)
uid = models.IntegerField(primary_key=True)
specification = models.CharField(max_length=255)
sale_price = models.IntegerField()
discount = models.IntegerField()
img1 = models.ImageField(max_length=255, null=True, blank=True, upload_to="images/")
img2 = models.ImageField(max_length=255, null=True, blank=True, upload_to="images/")
promote_method = models.TextChoices
terms_conditions = models.CharField(max_length=255, null=True)
promote_method = models.CharField(
max_length=20,
choices=promote_choices,
default='PPC'
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
这是我的 Html 部分,
#What i want to achieve is when i click on 'Get Link', it should redirect to
path('link/<int:uid>', views.link_view, name='link_view'),
但它在没有 slug 数据的情况下重定向。
<span>
<a class="Update" href="{% url 'link' %}">Get Link</a>
</span>
【问题讨论】:
-
你可以发布你的模型
-
完成,@SreevardhanReddy