Using urls names in viewsCapturing url parameters in request.GETHow to combine 2 or more querysets in a Django view?How can I get the full/absolute URL (with domain) in Django?How to get the current URL within a Django template?Why does DEBUG=False setting make my django Static Files Access fail?Need a minimal Django file upload exampleUse url args in views, is it possible?Django get the static files URL in viewDjango optional url parametersHow to reference urls by view path instead of name in Django 1.8?
Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
Resetting two CD4017 counters simultaneously, only one resets
Simple image editor tool to draw a simple box/rectangle in an existing image
Can a Bard use an arcane focus?
How can I successfully establish a nationwide combat training program for a large country?
Partial sums of primes
Fast sudoku solver
What would you call a finite collection of unordered objects that are not necessarily distinct?
Is it okay / does it make sense for another player to join a running game of Munchkin?
Meta programming: Declare a new struct on the fly
Is there enough fresh water in the world to eradicate the drinking water crisis?
Can a controlled ghast be a leader of a pack of ghouls?
When is separating the total wavefunction into a space part and a spin part possible?
Is it possible to build a CPA Secure encryption scheme which remains secure even when the encryption of secret key is given?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Calculating the number of days between 2 dates in Excel
How do I repair my stair bannister?
Blender - show edges angles “direction”
What does the "3am" section means in manpages?
What should I use for Mishna study?
Java - What do constructor type arguments mean when placed *before* the type?
Greatest common substring
Can I Retrieve Email Addresses from BCC?
Using urls names in views
Capturing url parameters in request.GETHow to combine 2 or more querysets in a Django view?How can I get the full/absolute URL (with domain) in Django?How to get the current URL within a Django template?Why does DEBUG=False setting make my django Static Files Access fail?Need a minimal Django file upload exampleUse url args in views, is it possible?Django get the static files URL in viewDjango optional url parametersHow to reference urls by view path instead of name in Django 1.8?
Is it possible to use urls names in views, like we can do it in template?
django django-views
add a comment |
Is it possible to use urls names in views, like we can do it in template?
django django-views
add a comment |
Is it possible to use urls names in views, like we can do it in template?
django django-views
Is it possible to use urls names in views, like we can do it in template?
django django-views
django django-views
asked Jan 13 '11 at 8:58
szamanszaman
3,585124071
3,585124071
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
(Updated answer to point to an existing url.)
add a comment |
Check out the docs on reverse
They have a specific example reversing a named url here:
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None)
viewname is either the function name
(either a function reference, or the
string version of the name, if you
used that form in urlpatterns) or the
URL pattern name.
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
add a comment |
<script>
var salesApiUrl = "% url 'URLNamesHere' %"
</script>
Now, the salesApiUrl is global. You can use the var name in js as well
add a comment |
I know this topic is years old, however during my own search for the same, this one popped up. I believe the requester is looking for the following in views.py:
views.py
class Overview(ListView):
model = models.data
template_name = "overview.html"
def get_queryset(self):
name = self.request.resolver_match.url_name
print(name)
Do note that I'm using class based views. Within regular views, the name can be retrieved as follows (not tested):
def current_url_name(request):
html = "<html><body>Url name is .</body></html>".format(request.resolver_match.url_name)
return HttpResponse(html)
The url name is within the (self.)'request' variable. From within your view, 'resolver_match.url_name' is the one you're looking for.
Hope this helps people in search of the same.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4678253%2fusing-urls-names-in-views%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
(Updated answer to point to an existing url.)
add a comment |
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
(Updated answer to point to an existing url.)
add a comment |
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
(Updated answer to point to an existing url.)
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
(Updated answer to point to an existing url.)
edited May 5 '17 at 16:01
aliqandil
681718
681718
answered Jan 13 '11 at 9:06
Daniel RosemanDaniel Roseman
457k42593651
457k42593651
add a comment |
add a comment |
Check out the docs on reverse
They have a specific example reversing a named url here:
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None)
viewname is either the function name
(either a function reference, or the
string version of the name, if you
used that form in urlpatterns) or the
URL pattern name.
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
add a comment |
Check out the docs on reverse
They have a specific example reversing a named url here:
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None)
viewname is either the function name
(either a function reference, or the
string version of the name, if you
used that form in urlpatterns) or the
URL pattern name.
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
add a comment |
Check out the docs on reverse
They have a specific example reversing a named url here:
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None)
viewname is either the function name
(either a function reference, or the
string version of the name, if you
used that form in urlpatterns) or the
URL pattern name.
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
Check out the docs on reverse
They have a specific example reversing a named url here:
https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls
reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None)
viewname is either the function name
(either a function reference, or the
string version of the name, if you
used that form in urlpatterns) or the
URL pattern name.
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
edited May 5 '17 at 11:54
aliqandil
681718
681718
answered Jan 13 '11 at 9:08
Yuji 'Tomita' TomitaYuji 'Tomita' Tomita
87.2k18227206
87.2k18227206
add a comment |
add a comment |
<script>
var salesApiUrl = "% url 'URLNamesHere' %"
</script>
Now, the salesApiUrl is global. You can use the var name in js as well
add a comment |
<script>
var salesApiUrl = "% url 'URLNamesHere' %"
</script>
Now, the salesApiUrl is global. You can use the var name in js as well
add a comment |
<script>
var salesApiUrl = "% url 'URLNamesHere' %"
</script>
Now, the salesApiUrl is global. You can use the var name in js as well
<script>
var salesApiUrl = "% url 'URLNamesHere' %"
</script>
Now, the salesApiUrl is global. You can use the var name in js as well
answered May 14 '18 at 9:40
Suman AstaniSuman Astani
580512
580512
add a comment |
add a comment |
I know this topic is years old, however during my own search for the same, this one popped up. I believe the requester is looking for the following in views.py:
views.py
class Overview(ListView):
model = models.data
template_name = "overview.html"
def get_queryset(self):
name = self.request.resolver_match.url_name
print(name)
Do note that I'm using class based views. Within regular views, the name can be retrieved as follows (not tested):
def current_url_name(request):
html = "<html><body>Url name is .</body></html>".format(request.resolver_match.url_name)
return HttpResponse(html)
The url name is within the (self.)'request' variable. From within your view, 'resolver_match.url_name' is the one you're looking for.
Hope this helps people in search of the same.
add a comment |
I know this topic is years old, however during my own search for the same, this one popped up. I believe the requester is looking for the following in views.py:
views.py
class Overview(ListView):
model = models.data
template_name = "overview.html"
def get_queryset(self):
name = self.request.resolver_match.url_name
print(name)
Do note that I'm using class based views. Within regular views, the name can be retrieved as follows (not tested):
def current_url_name(request):
html = "<html><body>Url name is .</body></html>".format(request.resolver_match.url_name)
return HttpResponse(html)
The url name is within the (self.)'request' variable. From within your view, 'resolver_match.url_name' is the one you're looking for.
Hope this helps people in search of the same.
add a comment |
I know this topic is years old, however during my own search for the same, this one popped up. I believe the requester is looking for the following in views.py:
views.py
class Overview(ListView):
model = models.data
template_name = "overview.html"
def get_queryset(self):
name = self.request.resolver_match.url_name
print(name)
Do note that I'm using class based views. Within regular views, the name can be retrieved as follows (not tested):
def current_url_name(request):
html = "<html><body>Url name is .</body></html>".format(request.resolver_match.url_name)
return HttpResponse(html)
The url name is within the (self.)'request' variable. From within your view, 'resolver_match.url_name' is the one you're looking for.
Hope this helps people in search of the same.
I know this topic is years old, however during my own search for the same, this one popped up. I believe the requester is looking for the following in views.py:
views.py
class Overview(ListView):
model = models.data
template_name = "overview.html"
def get_queryset(self):
name = self.request.resolver_match.url_name
print(name)
Do note that I'm using class based views. Within regular views, the name can be retrieved as follows (not tested):
def current_url_name(request):
html = "<html><body>Url name is .</body></html>".format(request.resolver_match.url_name)
return HttpResponse(html)
The url name is within the (self.)'request' variable. From within your view, 'resolver_match.url_name' is the one you're looking for.
Hope this helps people in search of the same.
answered Mar 7 at 9:59
Jens van HellemondtJens van Hellemondt
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4678253%2fusing-urls-names-in-views%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown