how to run the django server on hostname? - python

I wanted to run Django server on a hostname in the local system. Django has its own server ... that runs on the localhost:8000 i just want it to run on
cpanel-django.django-project.com:8000
I tried using:
python manage.py runserver cpanel-django.django-project.com:8000
i am getting this error:
Validating models...
0 errors found
March 06, 2014 - 06:21:24
Django version 1.6.2, using settings 'moclient.settings'
Starting development server at http://cpanel-django.django-project.com:8383/
Quit the server with CONTROL-C.
Error: [Errno -5] No address associated with hostname

You need to edit the hosts file and rename localhost to cpanel-django.django-project.com.

For every host name there is mapping of IP address in your system so that you don't need to worry about IP address, you just need to remember host name.
How to add Host name in your system?
Check this wiki: Host file content
Where to find the file in your system?
Location of file in different system is mentioned here

For windows , you can make an entry in hosts file , located in
C:\Windows\System32\drivers\etc\hosts
and update the file with
127.0.0.1 cpanel-django.django-project.com:8383
If you are running on port 80 ,
127.0.0.1 cpanel-django.django-project.com

Related

Run Flask on 127.0.0.2, get error "Can't assign requested address"

I heard that all the 127.x.x.x are loopback IPs. So I try to run Flask on 127.0.0.2 but It gets error "Can't assign requested address" instead. While it works fine on 127.0.0.1
So how can I run flask on 127.0.0.x ?
Looks like your OS is a MacOS. MacOS using only 127.0.0.1 for loopback interface
But it is possible to assign 127.0.0.XX aliases manually
This article has couple solutions how to do that
Maybe what you looking for is to expose flask api on a different host than localhost(127.0.0.1)
You can choose a different port
app.run(host="0.0.0.0", port=8888)
Or host with machine hostname
from socket import gethostname
gethostname()
For custom hostname, add it in /etc/hosts file, it probably already contains a line about 127.0.0.1, in which case you just add your alias to the list
127.0.0.1 localhost localhost.localdomain myappname
in app
app.config['SERVER_NAME'] = 'myappname:5000'
for public, you would need to configure a specific dns

In zulip dev environment, how can i access zulip's first dev web browser using run-dev.py in vagrant env but i can't access from global ip

I have some problem now using zulip dev-env ...
I did success-installation by Dev-env(using run-dev.py in vagrant env) in my Mac PC and then i could access the first-dev page successfully through my mac-pc's browser
But i have been trying to show the first page using Dev-dev in my cloud hosting service (like AWS or google Cloud hosting) for several days
but i could not access and could not show the first page by using global IP and browser
Which part must I change the setting environment?
(that is, I want to access my dev-env[using run-dev.py] by global IP
after that, i want to test... )
Now I am using a cloud hosting. Of course I opened port 9991 and etc...
I use vagrant env and succeed it in cloud host.
In vagrant ssh, I could access zulip by using curl 127.0.0.1:9991 and received a success message:
29/Sep/2016 00:42:04]"GET / HTTP/1.0" 302 0" from running console
but i cannot access it by host console like this
ai2#mrtalk:~/project/zulip$ curl 127.0.0.1:9991
curl: (7) Failed to connect to 127.0.0.1 port 9991: Connection refused
of course , i can't access http://182.162.90.79:9991/ through my pc browser
for this I tried like these
In zproject/dev_setting.py (I changed...these lines)
EXTERNAL_HOST = '0.0.0.0:9991' #orgin localhost but change 0.0.0.0
ALLOWED_HOSTS = ['localhost','182.162.90.79','0.0.0.0'] #orgin localhost but add + '182.162.90.79','0.0.0.0'
In Vagrantfile I changed this line:
config.vm.network "forwarded_port", guest: 9991, host: host_port, host_ip: 127.0.0.1, auto_correct: true
What is wrong with here? Or which part should I change my dev-setting?

Django Cannot Be Accessed From Localhost

It's kinda weird I cannot access django from localhost but I able to access it from local IP.
python manage.py runserver 0.0.0.0:8000
then when I try to access from
My host file
127.0.0.1 lmlicenses.wip4.adobe.com
127.0.0.1 lm.licenses.adobe.com
127.0.0.1 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com
0.0.0.0 gc.kis.scr.kaspersky-labs.com ff.kis.scr.kaspersky-labs.com ie.kis.scr.kaspersky-labs.com
I'm guessing something wrong with windows firewall or kaspersky,but I don't know what to do.
I've add exception to port 8000 and python.exe too
I cannot access localhost:8000 from my browser if I run python manage.py runserver
I don't know why that command cannot work in my laptop, but in my pc it just works.
====
ok, so my solution now is to use ipv6 and port 8000 which is
python manage.py runserver [::]:8000
Just try http://0.0.0.0:8000 instead of localhost:8000
Default localhost value is http://127.0.0.1
If you see the runerver result you have :
starting developement server at http://0.0.0.0:8000
Because you told that django server start at http://0.0.0.0:8000 when you run this command :
python manage.py runserver 0.0.0.0:8000
I'm also beginner to django, but I needed following things in order to run the server:
In settings.py, added ALLOWED_HOSTS as
ALLOWED_HOSTS = [
'elearning.com'
]
where elearning.com is my hostname. You can have multiple hosts separated with comma.
Used following command to run the server:
python manage.py runserver [::]:8000 or python manage.py runserver 0.0.0.0:8000 or python manage.py runserver 0:8000.
It will now listen to all interfaces. Read Django doc here.
Browsed to given hostname. In my case, it is http://elearning.com:8000/
I tried writing IP in ALLOWED_HOSTS but it didn't work, I could not open http://192.168.x.x:8000 in browser. Can anyone please correct me?
simply execute
python manage.py runserver
automatically you can access by localhost and for the extern access you could have access if not are it's locked the port 8000, for access to django admin use the next url:
http://127.0.0.1:8000/admin/
How your host file end up like this ?? . Can you test something.
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
My host file see everything is commented out. Can you do the same with your hosts file and give it a Try .. .
In the settings.py file in your project folder,
add '0.0.0.0' to the allowed host list.
Then save the file and run the command.Guess will work.

Running ubuntu vagrant server won't show anything on debian local browser

I've done this multiple times and never had an issue.
I'm trying to run a website on vagrant (trusty64) through shh on my Debian 8 Jessie x64.
I have used the same Vagrantfile n times before and it always worked perfectly but for I don't know what reason, on my new laptop, when I enter (on vagrant server - tried with sudo and without):
vagrant up
vagrant ssh
cd /opt/site/
python manage.py runserver 0.0.0.0:8000
nothing happens in console. It shows the usual:
System check identified 1 issue (0 silenced).
October 28, 2015 - 10:16:41
Django version 1.8.4, using settings 'settings.development'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
and when I type the ip:port in my local browser it just say:
This webpage is not available
ERR_CONNECTION_REFUSED
Any workaround for this ?
My vagrant config file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 512
end
config.vm.box = "trusty64"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.network "private_network", ip: "192.168.100.10"
config.vm.synced_folder ".", "/opt/site"
config.vm.hostname = "alexander"
end
As a mention: I tried multiple ports and still nothing. More, I have the exactly same configuration on another pc and it works flawless.
If changing the port forwarding doesn't work.You might also need to change in the settings of virtual box from NAT to Bridged Adapter.
The firewall will block incoming traffix on port 8000, so you will have to forward that port. Try adding this this to the configuration. you're using:
config.vm.network "forwarded_port", guest: 8000, host: 8080
and then browse to http://192.168.100.10:8080 it should work.
Also dont forget to privision your box again, or even restart just to be sure.
vagrant reload --provision
Why it works on your other machine is a mystery to me. Maybe there is no firewall, or the port is already forwarded?

Postgresql socket error when running Django's syncdb (mac OS 10.7.5)

I'm trying to run Django's syncdb operation and am getting the following error:
psycopg2.OperationalError: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I've read the answers to this question and have tried the following:
changing "listen_address" to "localhost" or "*" in /Library/PostgreSQL/9.1/data/potsgresql.conf
changing "host" to "localhost" in my settings.py file (for Django)
user is set to "postgres" with correct password in settings.py
(I restarted the postgresql server after each step.)
I've also checked my pg_hba.conf file to see if the Unix domain socket was accepting connections from all users (based on this page). Here's what I have there:
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
I never had this problem before. I somewhat recently upgraded to Lion and am working on a new virtualenv with the bare minimum of modules installed.
Found the answer courtesy of Bradley Ayers:
set "unix_socket_directory" to "/var/pgsql_socket/" in postgres.conf
executed following commands:
"$ sudo dscl . append /Groups/_postgres GroupMembership postgres"
"$ sudo chmod g+w,o+rx /var/pgsql_socket/"
restarted postgresql
your database is not running try
pg_ctl -D /usr/local/var/postgres start
assuming thats where your postgre data directory is

Categories

Resources