0

I am working on a project using Django, every time i wanna run the script, i enter the command line:

>python manage.py runserver

How can I create an exec file that will run this command and open the 127.8.0.0 address in my browser when i just click on it ?

Nguyễn Vũ Thiên
  • 761
  • 1
  • 9
  • 19
bendo97
  • 21
  • 6
  • 1
    Why an exe? If you are using windows create a .bat file that does that. If you are using a Mac or Linux create a shell script that runs it. There's no need to have to compile it. You could run the first command, putting it into the background, then run the second to launch a browser. If you are using chrome see https://stackoverflow.com/questions/34796888/how-to-open-google-chrome-from-terminal – Steve Mapes Apr 14 '21 at 10:50

1 Answers1

3

Just create a .bat file. Example like this:

start cmd /k "cd E:\OE_Monitoring && oenv\Scripts\activate.bat && cd src\oe_project && python manage.py runserver 127.0.0.1:8000"

General syntax

start cmd /k "cd YourPathFolder && YourVirtualEnvironment\Scripts\activate.bat && cd YourPath\FolderContainManagePy && python manage.py runserver your_address:your_port"

Or you can add default address and default port in your settings.py:

from django.core.management.commands.runserver import Command as runserver

ALLOWED_HOSTS = ['*']
runserver.default_port = '8000'
runserver.default_addr = '127.0.0.1'

And file script just need run python manage.py runserver instead of python manage.py runserver 127.0.0.1:8000

Another case: If location of script at drive D and you want run project at drive E, we need change drive first (example E: && cd your_path...), but I recommend put script into project folder.

start cmd /k "YourDrive: && cd YourFolder && YourVirtualEnvironment\Scripts\activate.bat && cd YourPath\FolderContainManagePy && python manage.py runserver your_address:your_port"
Nguyễn Vũ Thiên
  • 761
  • 1
  • 9
  • 19
  • but this wouldn't work on a computer that doesn't have python and the necessary packages installed. I want to create an automatic script that would run when you double click on it even when it's another user on his own computer. – bendo97 Apr 15 '21 at 06:55