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?













8















Is it possible to use urls names in views, like we can do it in template?










share|improve this question


























    8















    Is it possible to use urls names in views, like we can do it in template?










    share|improve this question
























      8












      8








      8


      1






      Is it possible to use urls names in views, like we can do it in template?










      share|improve this question














      Is it possible to use urls names in views, like we can do it in template?







      django django-views






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 13 '11 at 8:58









      szamanszaman

      3,585124071




      3,585124071






















          4 Answers
          4






          active

          oldest

          votes


















          1














          https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls



          (Updated answer to point to an existing url.)






          share|improve this answer
































            7














            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]))





            share|improve this answer
































              1














              <script>
              var salesApiUrl = "% url 'URLNamesHere' %"
              </script>


              Now, the salesApiUrl is global. You can use the var name in js as well






              share|improve this answer






























                1














                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.






                share|improve this answer






















                  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
                  );



                  );













                  draft saved

                  draft discarded


















                  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









                  1














                  https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls



                  (Updated answer to point to an existing url.)






                  share|improve this answer





























                    1














                    https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls



                    (Updated answer to point to an existing url.)






                    share|improve this answer



























                      1












                      1








                      1







                      https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls



                      (Updated answer to point to an existing url.)






                      share|improve this answer















                      https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse-resolution-of-urls



                      (Updated answer to point to an existing url.)







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited May 5 '17 at 16:01









                      aliqandil

                      681718




                      681718










                      answered Jan 13 '11 at 9:06









                      Daniel RosemanDaniel Roseman

                      457k42593651




                      457k42593651























                          7














                          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]))





                          share|improve this answer





























                            7














                            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]))





                            share|improve this answer



























                              7












                              7








                              7







                              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]))





                              share|improve this answer















                              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]))






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              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





















                                  1














                                  <script>
                                  var salesApiUrl = "% url 'URLNamesHere' %"
                                  </script>


                                  Now, the salesApiUrl is global. You can use the var name in js as well






                                  share|improve this answer



























                                    1














                                    <script>
                                    var salesApiUrl = "% url 'URLNamesHere' %"
                                    </script>


                                    Now, the salesApiUrl is global. You can use the var name in js as well






                                    share|improve this answer

























                                      1












                                      1








                                      1







                                      <script>
                                      var salesApiUrl = "% url 'URLNamesHere' %"
                                      </script>


                                      Now, the salesApiUrl is global. You can use the var name in js as well






                                      share|improve this answer













                                      <script>
                                      var salesApiUrl = "% url 'URLNamesHere' %"
                                      </script>


                                      Now, the salesApiUrl is global. You can use the var name in js as well







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 14 '18 at 9:40









                                      Suman AstaniSuman Astani

                                      580512




                                      580512





















                                          1














                                          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.






                                          share|improve this answer



























                                            1














                                            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.






                                            share|improve this answer

























                                              1












                                              1








                                              1







                                              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.






                                              share|improve this answer













                                              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.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 7 at 9:59









                                              Jens van HellemondtJens van Hellemondt

                                              112




                                              112



























                                                  draft saved

                                                  draft discarded
















































                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  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





















































                                                  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







                                                  Popular posts from this blog

                                                  AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                                                  Алба-Юлія

                                                  Захаров Федір Захарович