Get URL and port number from view

Jon

Is there a way of grabbing a subset of the URL in Django views.py?

I have tried request.build_absolute_uri() but that captures slightly more than I want.

E.G. If the URL was http://127.0.0.1:8000/jobs/new I would like to get http://127.0.0.1:8000/

Instead I end up getting the entire URL, with the page names.

I am wondering if there is a rootURL function in Django or something similar maybe?

debianplebian

This question has a few approaches which are:

Using request.get_host(),

<a href="http://{{ request.get_host() }}">Go back home</a>

Using href='/',

<a href="/">Go back home</a>

Or Using the root url defined in your url conf.

url(r'^mah_root/$', 'someapp.views.mah_view', name='mah_view'),

Then in your template:

<a href="{% url mah_view %}">Go back home</a>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to remove get parameter from url in django view

From Dev

MVC get variable from url (routing) in view?

From Dev

Get the port number from the process id in UNIX

From Dev

Get port number from ServiceHost

From Dev

Get server url and port from Tornado Web Framework

From Dev

how get socket port number from an accept call (C UNIX)

From Dev

Single regexp to get page URL but exclude port number from a full URL

From Dev

How to remove the :port number from the end of an IIS URL?

From Dev

how to remove port number from URL in apache tomcat if connector port is 8081

From Dev

Java | API to get protocol://domain.port from URL

From Dev

How to get the IP and Port number from bluemix?

From Dev

How to get Base URL with port number in codeigniter 3.0.3

From Dev

Removing a port number from a string

From Dev

How to get port number from an HTTP response, using Python?

From Dev

ASP.NET MVC - Get parameter value from URL in the view

From Dev

How to get URL from web view in long click?

From Dev

Get Page Number from Rewrited URL

From Dev

forward the domain and remove the port number from the URL

From Dev

How to get the port number from the URL using jQuery?

From Dev

how get socket port number from an accept call (C UNIX)

From Dev

Get server url and port from Tornado Web Framework

From Dev

How to get the PORT number it is listening on?

From Dev

Get view from url

From Dev

get the value from URL using number sign #

From Dev

get service name from port number

From Dev

How to fetch the Machine Name ,Protocol and Port number from URL format using regular expression?

From Dev

How to get SMTP host name and port number from webmail

From Dev

Redirect traffic to a domain with a port number without showing the port number in the URL

From Dev

Remove port number in image url?

Related Related

  1. 1

    How to remove get parameter from url in django view

  2. 2

    MVC get variable from url (routing) in view?

  3. 3

    Get the port number from the process id in UNIX

  4. 4

    Get port number from ServiceHost

  5. 5

    Get server url and port from Tornado Web Framework

  6. 6

    how get socket port number from an accept call (C UNIX)

  7. 7

    Single regexp to get page URL but exclude port number from a full URL

  8. 8

    How to remove the :port number from the end of an IIS URL?

  9. 9

    how to remove port number from URL in apache tomcat if connector port is 8081

  10. 10

    Java | API to get protocol://domain.port from URL

  11. 11

    How to get the IP and Port number from bluemix?

  12. 12

    How to get Base URL with port number in codeigniter 3.0.3

  13. 13

    Removing a port number from a string

  14. 14

    How to get port number from an HTTP response, using Python?

  15. 15

    ASP.NET MVC - Get parameter value from URL in the view

  16. 16

    How to get URL from web view in long click?

  17. 17

    Get Page Number from Rewrited URL

  18. 18

    forward the domain and remove the port number from the URL

  19. 19

    How to get the port number from the URL using jQuery?

  20. 20

    how get socket port number from an accept call (C UNIX)

  21. 21

    Get server url and port from Tornado Web Framework

  22. 22

    How to get the PORT number it is listening on?

  23. 23

    Get view from url

  24. 24

    get the value from URL using number sign #

  25. 25

    get service name from port number

  26. 26

    How to fetch the Machine Name ,Protocol and Port number from URL format using regular expression?

  27. 27

    How to get SMTP host name and port number from webmail

  28. 28

    Redirect traffic to a domain with a port number without showing the port number in the URL

  29. 29

    Remove port number in image url?

HotTag

Archive