Django runserver error when specifying port

后端 未结 4 484
粉色の甜心
粉色の甜心 2021-02-04 05:06

I have recently become accustomed to doing the following in my django projects so that I can test bowser compatibility on various OS (i.e. non-linux):

$ sudo ./m         


        
相关标签:
4条回答
  • 2021-02-04 05:14

    I guess the sudo command will run the process in the superuser context, and the superuser context lack virtualenv settings.

    You may try to call the python binary at your virtualenv explicitly, for example:

    sudo $(which python) manage.py runserver 0.0.0.0:80
    

    Make a shell script to set the virtualenv and call manage.py runserver, then sudo this script instead.

    #!/bin/bash
    source /home/darwin/.virtualenvs/foo/bin/activate
    cd /path/to/project/foo
    python manage.py runserver 0.0.0.0:80
    

    Replace /home/darwin/.virtualenvs/foo with the root of your actual virtualenv and /path/to/project/foo with the root of your project.

    0 讨论(0)
  • 2021-02-04 05:14

    Run
    manage.py runserver 0.0.0.0:8000
    ie. run the server in different port and not the default port 80
    while accessing the url use the port number

    0 讨论(0)
  • 2021-02-04 05:18

    Here's another solution, instead of creating shell script, just specify which python executable you want to use in the command:

    Assuming that your virtualenv container is called .virtualenvs and there's an env called myproject in it, this is command you have to write:

    $ sudo ~/.virtualenvs/myproject/bin/python manage.py runserver 0.0.0.0:80
    
    0 讨论(0)
  • 2021-02-04 05:32

    Building upon @Paulo_Scardine's anwser:

    If you want to keep your virtualenv environment variables, you can add the -E option to the sudo command:

    sudo -E $(which python) manage.py runserver 0.0.0.0:80
    
    0 讨论(0)
提交回复
热议问题