App Name

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

App Name

Aniket Aryamane
Hello,

If in the urls.py, I can write:
app_name = 'posts'
.
.
path(' ', views.home, name='home'),



then why it is required to refer url name (from the template) by the app_name value as:
{% url 'posts:home' %}

It should be referred instead by app_name variable like below:
{% url 'app_name:home' %}


What do you guys think?



Thanks,
Aniket.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ce6c2ef7-b463-43d5-bd57-5f2ca3d6fda6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: App Name

Franklin Sarmiento
Hi bro, you can use this 

{% url 'home' %}

the app_name isn't the namespace, the namespace is define on the main urls.py, if you haven't a namespace defined, so, with the name assined on the path() is sufficient

greetings!

____________________________________________________
Franklin Sarmiento
Full-stack developer
skype: franklin.s.dev
Twitter: @franklinitiel
linkedin: Franklin Sarmiento ( [hidden email] )
Teléfono(s): +57 320 490.79.64 / +58 426 273.8103 ( whatsapp )



El mié., 11 jul. 2018 a las 20:56, Aniket Aryamane (<[hidden email]>) escribió:
Hello,

If in the urls.py, I can write:
app_name = 'posts'
.
.
path(' ', views.home, name='home'),



then why it is required to refer url name (from the template) by the app_name value as:
{% url 'posts:home' %}

It should be referred instead by app_name variable like below:
{% url 'app_name:home' %}


What do you guys think?



Thanks,
Aniket.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ce6c2ef7-b463-43d5-bd57-5f2ca3d6fda6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMsjBKJHSyoFcdD8RXNPpH2QcKp%3De%3DCdyX8VCju_HAmuHzi2ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: App Name

ludovic coues
In reply to this post by Aniket Aryamane
That question should be posted on Django user, where people discuss on how to use django to build web site and web application. This list is for improving djnago.

Anyway.
The first argument of the url tag is the name of the URL you want. The most common way to specify an URL name is with the format "{app}:{url}". This let you have each app have an home view without conflict and you can still can fetch the URL from the right app.

The name of an app is always stored in a variable app_name. And URL won't alter the URL name you gave it. So if you ask for 'app_name:posts', you will get the URL named posts from the app with a variable app_name set to the value app_name.


Maybe you are thinking of relative URL name resolving, which would be an improvement to Django. What I mean is the url tag would recognize a special value as meaning "fetch that view from the current app".

In my opinion, either a blank app name or 'self' would be a better choice for that special value. And it would cause a lot of issue. It might break existing Django app, which is bad. It will make finding all references if an URL in you code harder as you need to search for both the absolute and the relative name version.


I hope this answer your questions and thanks for asking


On Thu, 12 Jul 2018, 03:55 Aniket Aryamane, <[hidden email]> wrote:
Hello,

If in the urls.py, I can write:
app_name = 'posts'
.
.
path(' ', views.home, name='home'),



then why it is required to refer url name (from the template) by the app_name value as:
{% url 'posts:home' %}

It should be referred instead by app_name variable like below:
{% url 'app_name:home' %}


What do you guys think?



Thanks,
Aniket.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ce6c2ef7-b463-43d5-bd57-5f2ca3d6fda6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.a

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAEuG%2BTa26uoFDhjUujV_iWsNtBzx_1fvb5G2G3yfotUTzxLEBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.