How to create superuser in django using Unix Environment - python

when I'm using Visual Studio Code for the Django project in windows Environment, for creating a superuser I'm using the below command.
(test) C:\Users\SAHEB\projects\project>python manage.py createsuperuser
this same Django project is deployed in Unix server, below is the path where whole project is deployed.
/apps/sample/python
but python manage.py createsuperuser this command is not working in Unix server from this path, what's the solution

from_the_docs: runserver is to start a server and not to create superuser.
from_the_docs: To create superuser run following command:
django-admin createsuperuser

python manage.py createsuperuser works on all platforms. I think it's because of your path. Type dir and press enter in your cmd (make sure you do it in your project directory) at let's see if there is a file called manage.py or not.
(test) C:\Users\SAHEB\projects\project>dir

Related

Cannot runserver from Pycharm using Vagrant Interpreter. Path for manage.py is wrong, don't know where to fix it

I'm trying to configure correctly Pycharm (for a Django project) + Vagrant, to launch the runserver remotely from my host machine (and thus enable debugging).
The command for such seems simple but the path is wrong, so it fails.
It tries to run
/home/vagrant/.virtualenvs/[myprojname]/bin/python /vagrant/[myprojname]/manage.py runserver 0.0.0.0:8000
Second parameter is wrong, it's missing either the initial /home/ or it isn' a relative path.
My run configuration
I'm running a host windows machine, and a vagrant ubuntu 20.10 guest VB.
I setup my remote interpreter with what I suppose are the right parameters.
In my vagrantfile I have setup the shared folder as following (Project name is PoeMogul)
config.vm.synced_folder "PoeMogul", "/home/vagrant/PoeMogul"
In my vagrant box, everything is setup fine (I think). I have my venv. In my /home/vagrant/PoeMogul dir i can see my working directory from PyCharm. I can manually (through vagrant ssh) run the server. But i cannot make Pycharm invoke the manage.py file correctly, it tries to access "/vagrant/..." and not "/home/vagrant/...".
To resolve the issue with the incorrect path in PyCharm, you should specify the correct path to the Python interpreter and the Django project in the Run Configuration.
In PyCharm, go to Run > Edit Configurations.
Click the plus sign (+) to create a new configuration, and select Django Server.
Give the configuration a name, such as "Vagrant Django Server".
In the Environment section, select the remote interpreter that you set up for your Vagrant virtual machine.
In the Host field, enter the IP address of the Vagrant machine, 0.0.0.0.
In the Port field, enter 8000.
In the Working directory field, enter the absolute path to your Django project in the Vagrant virtual machine, e.g. /home/vagrant/PoeMogul.
In the manage.py script field, enter the absolute path to the manage.py file in the Django project, e.g. /home/vagrant/PoeMogul/manage.py.
Click Apply and then OK to save the changes.
Now, when you run the Vagrant Django Server configuration in PyCharm, it should use the correct paths and start the Django development server on your Vagrant virtual machine, accessible at 0.0.0.0:8000 from your host machine.

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

Django: python manage.py migrate does nothing at all

I just started learning django, and as i try to apply my migrations the first problem occurs. I start the server up, type
python manage.py migrate
and nothing happens. No error, no crash, just no response.
Performing system checks...
System check identified no issues (0 silenced).
You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
May 01, 2017 - 11:36:27
Django version 1.11, using settings 'website.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
python manage.py migrate
And that's the end of my terminal feed.
I thought maybe it just looks like nothing happens, but no. The changes weren't applied and I can't proceed any further. Any ideas on what's going on?
Well, you say that you first start the server and then type in the commands. That's also what the terminal feed you shared shows.
Do not run the server if you want to run management commands using manage.py.
Hit Ctrl+C to exit the server and then run your migration commands, it will work.
Try:
python manage.py makemigrations
python manage.py migrate
#adam-karolczak n all
If there are multiple DJANGO Projects, it can happen that DJANGO_SETTINGS_MODULE is set to some other app in environment varibles, the current project manage.py will not point to current project settings thus the error.
So, confirm DJANGO_SETTINGS_MODULE in fact points to the settings.py of current project.
Close the project if its running viz. ctrl+C.
You can also check the server is not running ( linux ) by
ps -ef | grep runserver
Then kill the process ids if they exist.
If you confirmed settings.py in DJANGO_MODULE_SETTINGS is for the project you are having issue.
Run the following it should resolve.
python manage.py makemigrations
python manage.py migrate
Hope it helps.
I was getting the same error
running this 2 command in terminal
python manage.py makemigrations
python manage.py migrate
and then
python manage.py runserver
solved my issues.
Thanks
Have you tried with parameter?
python manage.py makemigrations <app_name>
I had the same issue and the problem was that there was a pg_dump script running at the same time I was trying to migrate. After the dump was completed, migrations ran successfully.
Check that INSTALL_APPS app exists, if not add it
Checks the model for default attributes
Running this 2 command in terminal
python manage.py makemigrations
python manage.py migration
First exit of the present web server by typing Ctrl + C
Then run python manage.py migrate
The Warning is due to not configuring the initial database or migrating.

Manage.py runserver for demonstration

How would I run a Django application on, a digitalocean droplet let's say, with just using the development server Django provides. I've tried just running python3 manage.py runserver, but I can't pull it up with the browser from another computer
I know this is bad practice, but I really only need it up to demonstrate for a class project
by default runserver only listn on 127.0.0.1 that is not accessible from remote computer.
run
python3 manage.py runserver 0.0.0.0:8000
will solve it, simply check the real IP if the machine and use it as address in your browser
python3 manage.py runserver <your IP address>:8000

manage.py flag to force unattended command?

I am reading this tutorial: Installing and Configuring Graphite and Statsd on an Ubuntu 12.04 VPS
and I am working to automatize everything is possible then there is one step of this tutorial that is giving me crazy:
Next, we will configure the Graphite database. Go to the Graphite
webapp directory and run the database script:
cd /opt/graphite/webapp/graphite/
sudo python manage.py syncdb
As you see, we have to run the manage.py and when I run syncdb ask about a creation of superuser. How can I avoid that? I would like to run these sending all parameters to make an automatic script.
Any ideas?
You can use the --noinput argument to disable those prompts for the syncdb command.
--noinput
Use the --noinput option to suppress all user prompting, such as “Are you sure?” confirmation messages. This is useful if django-admin.py is being executed as an unattended, automated script.

Categories

Resources