Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: how to pass individual setting to manage.py

I'm looking for a way to override/define some individual django setting from command line without additional settings files.

What I need right now is to set the DEBUG setting or logging level each time when I run my management command. But it would be nice to be able to set anything.

like image 390
raacer Avatar asked Dec 19 '11 15:12

raacer


People also ask

What need to set in settings py to tell Django which host to use when connecting to database?

If you want to connect through TCP sockets, set HOST to 'localhost' or '127.0.0.1' ('host' lines in pg_hba.conf ).

What is the difference between Django admin and manage py?

Django-admin.py: It is a Django's command line utility for administrative tasks. Manage.py: It is an automatically created file in each Django project. It is a thin wrapper around the Django-admin.py.


1 Answers

In settings.py you can check for command line arguments, like this:

import sys

# for testing
if "--enable-wiki" in sys.argv:
    ENABLE_WIKI = True
    sys.argv.remove("--enable-wiki")

Usage:

./manage.py test --enable-wiki MyApp.tests
like image 90
Ramon Avatar answered Oct 04 '22 17:10

Ramon