Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Django to get the name for the host server?

How to use Django to get the name for the host server?

I need the name of the hosting server instead of the client name?

like image 845
user469652 Avatar asked Nov 04 '10 04:11

user469652


People also ask

How do I find my Django server URL?

Run the following command to start the Django server. Execute the following URL from the browser to display the domain name of the current URL. The geturl1() function will be called for this URL that will send the domain name to the index. html file.

What is the name of Django server?

Django comes with its own development server, python manage.py runserver , which you would use to develop locally. For more production-ready deployments, a popular choice is Nginx backed by uWSGI or Gunicorn.

Does Django has its own server?

Django uses their own web server, which is not supposed to be used in a production setting. DO NOT USE THIS SERVER IN A PRODUCTION SETTING.


2 Answers

I generally put something like this in settings.py:

import socket  try:     HOSTNAME = socket.gethostname() except:     HOSTNAME = 'localhost' 
like image 72
Craig Trader Avatar answered Sep 25 '22 06:09

Craig Trader


If you have a request (e.g., this is inside a view), you can look at request.get_host() which gets you a complete locname (host and port), taking into account reverse proxy headers if any. If you don't have a request, you should configure the hostname somewhere in your settings. Just looking at the system hostname can be ambiguous in a lot of cases, virtual hosts being the most common.

like image 24
Tobu Avatar answered Sep 24 '22 06:09

Tobu