How to handle parameters in Django view

Asked 2 years ago, Updated 2 years ago, 48 views

Hi, everyone. This is a question about how to receive parameters from the long view.

View and url are

def actress_detailview(request, name):
    actresses = EnActress.objects.filter(name=name)
    jpname = JpConvert.objects.filter(enname=name)
    context = {'actresses': actresses, 'name': name, 'jpname':jpname}
    return render(request, 'dmmactress/actress_detail.html', context)

url(r'^actress/(?P<name>.*)/$', views.actress_detailview, name='actress_detailview'),

This is.

Two models

class EnActress(models.Model):
    name = models.CharField(max_length=100, null=True)

class JpConvert(models.Model):
    enname = models.CharField(max_length=100)
    jpname = models.CharField(max_length=100)

Each of the name and name fields in contains the same data (in different order), so you want to take the name from the view and two attributes and jpname as parameters and present it in the template.

However, the view I created does not show {{jpname.enname}} in the template. Is there a problem with the code I wrote? Should a query set with the same data receive the same parameters? I don't know

Please give me some advice.

django python

2022-09-22 13:15

1 Answers

jpname = JpConvert.objects.filter(enname=name)where jpname is None, {{jpname.enname}}You might not be able to see the . Did you check it out?


2022-09-22 13:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.