*Hi all,* *I am having issues using arguments from a URL in another view, I have reached out on stackover flow with no success, i believe i am wording this question poorly.*
*To quickly explain * - *I have a main site which shows a list of sports clubs. When the user selects on one it renders that specific club home page using the PK passed in the template.* - *Once I get to this home page e.g. http://127.0.0.1:8000/club_home/2/ . I have many sub-pages which a user can select but I have no idea how I can use that same PK to filter data in the other pages to only show details based on that club.* - *I would also like to include that PK in the rest of the URLs. e.g. http://127.0.0.1:8000/club_home/2/teams/* *Code:* *index.html:* <h2>Our Clubs</h2> {% for club in all_clubs %} <a href="{% url 'clubs:club_home_with_pk' pk=club.pk %}"> <li>{{ club.club_name }}</li> </a> {% endfor %} *urls.py* ****I understand I must include the <int:pk>/ before teams in the URL but I am unsure how to pass in that argument**** urlpatterns = [ path('', views.club_home, name='club_home'), path('<int:pk>/', views.club_home, name='club_home_with_pk'), path('teams/', views.TeamInfo.as_view(), name='teams'), ] *views.py * def club_home(request, pk=None): if pk: club = ClubInfo.objects.filter(pk=pk) club_posts = ClubPosts.objects.filter(club_id=club[0]) elif request.user.is_authenticated: club = ClubInfo.objects.filter(user=request.user) club_posts = ClubPosts.objects.filter(club_id=club[0]) # photo = model.club_logo.ImageField(storage=profile_pics) args = {'club': club, 'club_posts': club_posts } return render(request, 'club_home_page.html', args) class TeamInfo(APIView): renderer_classes = [TemplateHTMLRenderer] template_name = 'teams.html' def get(self, request): serializer = TeamSerializer() user = ClubInfo.objects.filter(user=request.user).first() teams = Team.objects.filter(club_id=user.pk) return Response({'serializer': serializer, 'teams': teams, }) *club_main_page.html* ****navbar on club home page to get to other pages, I know I need to include <pk> into the **URL and** I need to pass this argument into the href of this URL but as need to figure out the view before adding this **** <li><a class="navbar-link" href="{% url 'clubs:teams' %}">Team</a></li> *Any idea what I need to add into the view to allow for this. I would really appreciate any help as I've been stuck on this for weeks now. * *Thanks * *Gavin* -- __ Séanadh Ríomhphoist/_ Email Disclaimer__ ** Tá an ríomhphost seo agus aon chomhad a sheoltar leis faoi rún agus is lena úsáid ag an seolaí agus sin amháin é. Is féidir tuilleadh a léamh anseo. <https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml> <https://www4.dcu.ie/iss/seanadh-riomhphoist.shtml>* _ This e-mail and any files transmitted with it are confidential and are intended solely for use by the addressee. Read more here. <https://www4.dcu.ie/iss/email-disclaimer.shtml> _ *_ -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3465a2fc-347a-4096-b037-83be9b57d8a2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.