Home > Blockchain >  How can I change the sites url depending on the anchor tags?
How can I change the sites url depending on the anchor tags?

Time:06-23

urls.py

app_name='listing'

urlpatterns = [
    url(r'^listing/select/$',views.platformselect,name='listingselect'),
    url(r'^listing/',views.listingpage,name='listingpage'),

]

views.py

def platformselect(request):
    
    return render(request,'listing/platform_select.html')

platform_selection.html

<a href="{% url 'listing:listingpage' %}">amazon</a>
<a href="{% url 'listing:listingpage' %}">ebay</a>
<a href="{% url 'listing:listingpage' %}">google</a>

Greetings. How can I change the urls according to the options. For example when I click the 'amazon' anchor tag I want it go to "mysite.com/listing/amazon". Same for the other options. How can I change the sites url depending on the anchor tags?

CodePudding user response:

You may need to make slight changes according to your project:

In your urlpatterns:

path("listing/<int:id>/", views.listing_detail, name="listing-detail"),

In your template:

<a href="{% url 'listing:listing-detail' listing.id %}">{{ listing.name }}</a>

In your view function:

def listing_detail(request, id):
    listing = Listings.objects.get(id=id)
    return render(request, "listing/listing_detail.html", {
        "listing": listing
    }) 
  • Related