0

I'm trying to get the hang of Django URL namespaces. But I can't find any examples or documentation.

Here is what I have tried.

foo.urls

from django.urls import path, include
from Foo.Views import FooView


app_name ="Foo"

urlpatterns = [
path('', referansView.referans_listele , name="foo"),
path('create/', olusturView.referans_olustur, name="foo_create"),
]

foo.html

<a class="btn btn-success"
   href="{% url '{{foo}}:{{foo_create}}' %}?r=Foo:  {{request.resolver_match.url_name}}">

fooview.py

from django.shortcuts import render
from Foo.models import FooModels

def foo_create(request):
    result ={"Foo":"Foo"}
    return render(request,"referanslar.html", result)

What I want is to be able to browse to /foo/X

7
  • Using foo everywhere has made your example very confusing. It looks as if you want {% url 'Foo:foo_create' %} (Foo with a capital F because you have app_name = 'Foo'). Commented Apr 18, 2019 at 14:33
  • Thank you for asking. Actually I want to write dynamically this code ({% url 'Foo:foo_create%}') . How can make dynamically {%url {{foo}}:{{foo_create}} %} with context variables in django template Commented Apr 18, 2019 at 14:43
  • As I said, your example code is confusing. You don't have foo or foo_create in the template context, only 'Foo'. Perhaps you can use the add filter, e.g. {% url foo|add:':'|add:foo_create %}. Commented Apr 18, 2019 at 15:35
  • I am so sory. I edit the view in Django Project. This code is like below from django.shortcuts import render from Foo.models import FooModels def foo_create(request): result ={"Foo":"Foo_appName","fooView":"fooView" } return render(request,"referanslar.html", result) Commented Apr 19, 2019 at 8:43
  • Then you would do {% url Foo|add:':'|add:fooView %}. However, it might be simpler to pass {'fooView': 'Foo:fooView'}` to the template and do {% url fooView %}. Or you could pass the reversed url to the template with {'foourl': reverse('Foo:fooView')}, then use {{ foourl }}. Commented Apr 19, 2019 at 8:57

1 Answer 1

0

You can include the urls in main site urls like

path('foo/', include('foo.urls')),
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.