so when I'm im in my root directory (where manage.py lives), if I do manage.py runserver it says command not found. I have to do ~/<project_name>/manage.py runserver for it to work. Why is this?
You can add manage.py to your bash as a alias to easily access it.
Add
alias <key>=“~/<project_name>/manage.py runserver”
Add it to ~/.bashrc file (create if doesn’t exists
Replace key with code you prefer like mnrun and rerun bash and type mnrun
In manage.py runserver, the manage.py is only a file, not a command! You can not do this since the Linux(shell) could only execute binary executable image.
If you want to run manage.py without python, you could add (supposed that you used Linux)
#!/usr/bin/env python
at the head of manage.py, and make it executable with chmod +x manage.py.
And now, you could run ./manage.py runserver
Related
I just want to call this command : django-admin manage.py runserver but it always fails and it gives me this message instead:
(No Django settings specified. Unknown command: 'manage.py')
what can I do ?
Go to the folder where your manage.py file is located nad run
./manage.py runserver or python manage.py runserver
The real command is:
python manage.py runserver
your version with django is incorrect.
django-admin using for creating project
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
After that's enough to run the below command for running the project:
➜ django-admin runserver
or run the below command in the base directory of project:
➜ python manage.py runserver
How to do run: python manage.py runserver in Visual Studio Code?
I get the below error
"Can not open file manage.py:no such file or directory"
go to that folder where is you 'manage.py' file through cm
Folder name
and then run you command
python3 manage.py runserver
In vscode terminal (Ctrl+\ hotkey) change path (with cd command) to directory where manage.py file of your project saved, and then run python manage.py runserver
I'm using Django1.11.5 and I created makemessages.py file in "my-app/management/commands/" directory to customise makemessages command.
And I made it to execute this command by running "python ../manage.py makemessages" from my-app directory.
But I want to execute by "django-admin makemessages -l ja".
(Running "django-admin makemessages -l ja" just executes default makemessages command)
Is there any way to execute this customised command by running "django-admin makemessages -l ja"?
I believe it should work if you did all right. Take a look at this docs part:
In addition, manage.py is automatically created in each Django
project. manage.py does the same thing as django-admin but takes care
of a few things for you:
It puts your project’s package on sys.path.
It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your
project’s settings.py file.
Carefully check this two moments. Since your manage.py works as expected, you already added your app in INSTALLED_APPS (after that Django can find and override default management command).
I'm writing a startup.sh script to be ran when a docker container is created.
#!/bin/bash
python manage.py runserver
python manage.py makemigrations accounts
python manage.py migrate
python manage.py check_permissions
python manage.py cities --import=country --force
*python manage.py shell | from cities.models import * Country.objects.all().exclude(name='United States").delete()*
python manage.py cities --import=cities
python manage.py cities --import=postal_code
I am guessing the line in question is incorrect, what would be the correct way to do this in a bash script?
Use a heredoc:
python manage.py shell <<'EOF'
from cities.models import *
Country.objects.all().exclude(name='United States').delete()
EOF
It's not such a good idea to include django code in a shell script file. It's better to either make a python file and put those code in it and do:
python manage.py shell < script.py
Or better, write a django management command. In this way you could track your code in the same project/repo and people got less confused when they see this.
After running:
$ ./manage.py migrate I am getting the following error:
-bash: ./manage.py: Permission denied
Trying to run a migration after making a change in the DB.
Any advice would be really appreciated.
You need to make manage.py executable to excecute it. Do chmod +x manage.py to make it excecutable. Alternately you can do python manage.py <cmd> instead.
To give yourself execute permission for the file containing the script use the command:
chmod u+rwx filename.py
To give other users permission to read and execute but not alter the shell script use:
chmod go+rx filename.py
reference http://unixhelp.ed.ac.uk/scrpt/scrpt1.2.html
You can try to use
python manage.py migrate
instead of .
/manage.py migrate
I typed su root space after root and it worked.
root was my admin password then the CMD after with a space after the admin password.