How to run the django-admin manage.py runserver - python

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

Related

How to do run:"python manage.py runserver in vscode.i want to run a new server for my project

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

how to call different settings from manage.py in django

I'm trying to call environment specific settings in django.
I found that you can do something close in django admin according to: https://docs.djangoproject.com/en/2.0/topics/settings/#the-django-admin-utility
I tried this with the manage.py:
python3 manage.py runserver --settings=mysite.settings.prod_settings
I get the error:
ModuleNotFoundError: No module named 'mysite.settings.prod_settings';
'mysite.settings' is not a package
How can I call environment specific settings?
Thanks
I changed the command to:
python3 manage.py runserver --settings=mysite.prod_settings
because I have a file called prod_settings.py and it worked.

how to use manage.py inexplicitely

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

Is there any way to execute custom makemessages command by running "django-admin makemessages -l ja"?

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).

Can't seem to setup my Django project properly

I was trying the official tutorial of Django because I want to learn it. I run Archlinux 4.10.11-1 64 bits.
First, I created a folder named djangoapp where I set my virtual environment:
$ virtualenv djangoapp
I set my current directory to this folder, and then I activated it:
$ source bin/activate
And I installed Django after:
$ pip install django
Following the tutorial, I ran:
$ django-admin startproject djangoapp
And set my current directory to djangoapp, and ran:
$ python manage.py runserver
But I'm getting the following error:
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Indeed, running env | grep DJANGO_SETTINGS_MODULE gets me the following result:
DJANGO_SETTINGS_MODULE=
So I tried to set it manually:
$ export DJANGO_SETTINGS_MODULE='djangoapp.settings'
Running $ python manage.py runserver now works, but $ django-admin help now gets me the following error:
ModuleNotFoundError: No module named 'djangoapp'
What did I do wrong? Thanks for your help!
PS: $ python --version gets me Python 3.6.1.
I think the docs could be a little clearer about this, but django-admin is typically only used for running django-admin startproject and manage.py is used for the rest e.g. ./manage.py runserver, ./manage.py migrate etc.
Deleting the DJANGO_SETTINGS_MODULE environment variable should allow you to run both ./manage.py * and django-admin startproject commands when inside the djangoapp folder.
I'm not sure how to do this on Archlinux, but something like unset DJANGO_SETTINGS_MODULE or set -e DJANGO_SETTINGS_MODULE should work.
Further info: you can think of manage.py as a wrapper around django-admin that automatically sets the PYTHONPATH and DJANGO_SETTINGS_MODULE environment variables. Therefore, once inside the project, you can just use ./manage.py rather than django-admin to run the management commands.

Categories