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.
Related
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
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.
I installed Anaconda with Python, added some more packages and tried to run Django development python manage.py runserver 0.0.0.0. It's running fine but I can't access it remotely from some reason. My server on other port is working fine and firewalls are all set. I found others had this problem and they simply run it as superuser sudo python manage.py runserver 0.0.0.0.
My problem is that when running as superuser, it will use different Python (or at least that's what it looks like). It is same 2.7.12 version (but no Anaconda suffix) and there are no required packages, so I can't run server.
I'm not really experienced with Linux. I tried to remove Python from root and passing env variables, but that didn't help. How can I run python as superuser and use Python with packages from my user.
Try sudo running your local python, like
sudo /home/YourAnaconda_bin/python manage.py runserver 0.0.0.0
I'm very new to this whole setup so please be nice.
On dev the command usually works with no errors but since I have been experimenting with different commands for Django someting has gone wrong.
python manage.py runserver 0.0.0.0:80
I don't have permission to use this port anymore. I can use port 8080 but the website doesn't work when I add the port to the end of the usual host name in the url. When I used port 80 I never had to add :80 to the url anyway.
I had an error where I didn't have permissions to the log file but I changed the permissions on that file. It seems there is now many things I don't have permissions for.
Django 1.8.5.
Using a virtual envirnment and I have 2 apps in the project.
If you're on Linux, you'll receive this error.
First and foremost, Django does not have a production server, just a very basic development server and uses port 8080 by default.
when you execute the command
python manage.py runserver
you tell django to start its development server and it runs so you can test your web app before deployment to a production server.
Django Documentation -> django-admin -> Run Server
The way to access the server is to use your browser and plug in the URL in the address bar as so
localhost:8080
by default, most HTTP applications run on port 80 unless otherwise stated. For example, your MySQL server could run on port 3306 by default.
Basically, you can think of ports as old school telephone lines that connect you to whom ever your looking to communicate with.
There's nothing really special about any of this. You should probably play with bottle to get the basics down first; just a friendly suggestion.
You can dig in to the details on the website. While not secure, you can use sudo to run on port 80, but for security reasons you should avoid it.
#mtt2p mentions a serverfault post that does a great job of the why
I'm sure there's a way to tell the server to allow only local connections, but you should only use 0.0.0.0:80 when you want to show off your work to other people or see what your web app looks like on other devices.
In the long run, sudo is just easier and quicker, but lazy and insecure.
This is a link that explains it in the context of a virtualenv.
Django runserver error when specifying port
The answer states
I guess the sudo command will run the process in the superuser
context, and the superuser context lack virtualenv settings.
Make a shell script to set the virtualenv and call manage.py
runserver, then sudo this script instead.
You should note that the answer explaining a virtualenv based context is also insecure. It should just be run as
sudo python manage.py runserver 80
not
sudo bash script-name
outside of a virtualenv. Doing so defeats the purpose of sand-boxing your application. If you ignore this, you'll be exposing yourself to a race condition.
I am in Xubuntu 20.04 version and I use this command (because I have an python env) :
$ sudo ~/.virtualenvs/myproject/bin/python manage.py runserver 0.0.0.0:80
And to know where is your envs python folder, I did :
$ which python
sudo python manage.py runserver 0.0.0.0:80
you need admin rights for port 80
I set up a virtualenv called "aira" and installed virtualenvwrapper in the root environment (my virtualenvwrapper settings in /root/.bashrc are at the bottom). This reduces the number of sudo commands I need to cascade to -c together to get runserver working:
sudo sh -c "workon aira && python manage.py runserver --insecure 0.0.0.0:80"
If you've set up your django app's virtualenv without virtualenvwrapper you'll need to manually change to the correct directory and activate your virtualenv within the sudo command sequence. My virtualenv is called aira and I keep my virtualenvs in /root/.virtualenvs. My django project is in the ubuntu user's home directory:
sudo sh -c "source $HOME/.virtualenvs/aira/bin/activate && cd /ubuntu/src/aira/ && python manage.py runserver --insecure 0.0.0.0:80"
If you've installed django and your requirements.txt in the system site packages then you can use sudo to runserver.
sudo python manage.py runserver --insecure 0.0.0.0:80"
The --insecure option allows staticfiles to serve your static assets (images, css, javascript).
For completeness, here're my virtualenvwrapper configuration variables in /root/.bashrc on Ubuntu 16.04:
# python3 is used for virtualenv and virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
# *root* reuses the virtualenvs in *ubuntu*'s home directory
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=/home/ubuntu/src
source /usr/local/bin/virtualenvwrapper.sh
sudo ./venv/bin/python manage.py runserver 80
I am having difficulty running Django on my Ubuntu server. I am able to run Django but I don't know how to run it as a service.
Distributor ID: Ubuntu
Description: Ubuntu 10.10
Release: 10.10
Codename: maverick
Here is what I am doing:
I log onto my Ubuntu server
Start my Django process: sudo ./manage.py runserver 0.0.0.0:80 &
Test: Traffic passes and the app displays the right page.
Now I close my terminal window and it all stops. I think I need to run it as a service somehow, but I can't figure out how to do that.
How do I keep my Django process running on port 80 even when I'm not logged in?
Also, I get that I should be linking it through Apache, but I'm not ready for that yet.
Don't use manage.py runserver to run your server on port 80. Not even for development. If you need that for your development environment, it's still better to redirect traffic from 8000 to 80 through iptables than running your django application as root.
In django documentation (or in other answers to this post) you can find out how to run it with a real webserver.
If, for any other reason you need a process to keep running in background after you close your terminal, you can't just run the process with & because it will be run in background but keep your session's session id, and will be closed when the session leader (your terminal) is terminated.
You can circunvent this behaviour by running the process through the setsid utility. See your manpage for setsid for more details.
Anyway, if after reading other comments, you still want to use the process with manage.py, just add "nohup" before your command line:
sudo nohup /home/ubuntu/django_projects/myproject/manage.py runserver 0.0.0.0:80 &
For this kind of job, since you're on Ubuntu, you should use the awesome Ubuntu upstart.
Just specify a file, e.g. django-fcgi, in case you're going to deploy Django with FastCGI:
/etc/init/django-fcgi.conf
and put the required upstart syntax instructions.
Then you can you would be able to start and stop your runserver command simply with:
start runserver
and
stop runserver
Examples of managing the deployment of Django processes with Upstart: here and here. I found those two links helpful when setting up this deployment structure myself.
The problem is that & runs a program in the background but does not separate it from the spawning process. However, an additional issue is that you are running the development server, which is only for testing purposes and should not be used for a production environment.
Use gunicorn or apache with mod_wsgi. Documentation for django and these projects should make it explicit how to serve it properly.
If you just want a really quick-and-dirty way to run your django dev server on port 80 and leave it there -- which is not something I recommend -- you could potentially run it in a screen. screen will create a terminal that will not close even if you close your connection. You can even run it in the foreground of a screen terminal and disconnect, leaving it to run until reboot.
If you are using virtualenv,the sudo command will execute the manage.py runserver command outside of the virtual enviorment context, and you'll get all kind of errors.
To fix that, I did the following:
while working on the virtual env type:
which python
outputs: /home/oleg/.virtualenvs/openmuni/bin/python
then type:
sudo !!
outputs: /usr/bin/python
Then all what's left to do is create a symbolic link between the global python and the python at the virtualenv that you currently use, and would like to run on 0.0.0.0:80
first move the global python folder to a backup location:
mv /usr/bin/python /usr/bin/python.old
/usr/bin/python
that should do it:
ln -s /usr/bin/python /home/oleg/.virtualenvs/openmuni/bin/python
that's it! now you can run sudo python manage.py runserver 0.0.0.0:80 in virtaulenv context!
Keep in mind that if you are using postgres DB on your developement local setup, you'll probably need a root role.
Credit to #ydaniv