Django manage.py error when run from a shell script - python

When I type and execute the command python manage.py runserver localhost:8080 directly in the terminal everything works fine but when I place the command inside a shell script I get the following error:
The script contains the following:
Does anyone know why this is happening?

There are spaces in the script after runserver.
You should remove these to ensure you're only running the desired command without any indication of host / port.

Related

How to run Django project in background

Recent I am running Django project on terminal using this command:
python manage.py runserver 0.0.0.0:80
But Server is stopped by closing terminal, So I need to run server in background.
How can I solve this issue?
You can use the nohup command, so your command runs without the terminal and all the outputs from the program will go to the file nohup.out (in the same directory you ran the command).
Use like so:
nohup python manage.py runserver 0.0.0.0:80
You can use screen to run a program in background.
This should answer your question
You may try:
python manage.py runserver 0.0.0.0:80 &
"&" puts the executed command in background and sets init as it's parent process when you close the terminal
You can run nohup, an output of the command will not be set what will not be created in the command (where or was executed)
nohup python manage.py runserver 0.0.0.0:8000
If you are using some automation software, in order not to crash the deployment, add an '&' at the end of the command, like this
nohup python manage.py runserver 0.0.0.0:8000 &

Django manage.py migrate command cannot access Linux environment variables

Python cannot access environment variables while running any command. For example, after running
python3 manage.py migrate
an error occurs:
django.db.utils.OperationalError: (2006, "Access denied for user 'dbmasteruser'#'0.0.0.0' (using password: YES)")
But if I insert a plain string value for database password instead of os.environ.get('PASSWORD'), command works fine.
All environment variables are written in setenv.sh file, but I have also tried to set them alternatively using command export PASSWORD=password.
Executing command using sudo doesn't work either.
However, Apache deployment server can read those environment variables without any issues, but the problem occurs while running migrations or any other command. How can I solve it?

'django' is not recognized as an internal or external command,

I have been using django commands in my virtual environment for a longtime....
suddenly today
When i run this command in my cmd from my Anaconda Env.....
django manage.py runserver
cmd responded with this
'django' is not recognized as an internal or external command,
operable program or batch file.
when i ran the command "conda list" it shows django package in the list...
do anyone know a solution to this??
You should run it with python
python manage.py runserver
And make sure you have Django installed properly, and keep in mind you won't use anaconda for Django. Plus, if you're starting a project, the proper command will be
django-admin startproject project_name
Call Django with django-admin. Not exactly intuitive, but this is how Django works.

PHP - Execute python script on remote IP address and get result

here is what I am trying to do:
I have a PHP application running on a web server. There is also an other virtual machine (in the same network with the appropriate permissions) where there is a python script. Now, what I want to do is from the PHP to run the python script on the remote machine and get back the result.
The following code runs correctly on the cmd on the server.
cd C:\pstools
psexec.exe \\192.168.0.ip cmd
cd "path of the python script on the remote machine"
python main.py
This works great and returns the result.
Now... how do I run this from PHP? I already tried with exec commands and I also tried with .bat file. I mean, to right the code on a batch file and execute it with the exec command through PHP.
The batch files looks like this:
cd /d C:\pstools
psexec.exe -h -accepteula \\192.168.0.ip cmd
cd "path of the python script on the remote machine"
python main.py
This finishes without an error, but doesn't seem to actually run the cmd on the remote machine. I've also tried some variations of the psexec command, like adding the path of the file on the same command, but still no luck.
Any idea on how to address this would be appreciated!
Thank you all in advance :)

Preventing Blocking of os.system

I'm trying to run multiple Django development server using a python script, normally I run the server using a terminal command "python manage.py runserver PORTNumber". I want to be able to run multiple instances on different ports, but when trying to use os.system, I get blocked; I made a thread that contained the os.system command, but when opening it I get blocked too. Any ideas how to prevent that, or a way around to run the development server on multiple ports ?
Thanks in advance.

Categories

Resources