'Manage.py behave' not recognised as command in Django project - python

I've had to clone a repository involving a django project.
This is my first time using django and the project is configured a bit differently than what a normal django project would be. For instance it has a settings folder with a local.py file that contains a Local(Dev) class. I have installed behave_django, however when I run the command 'manage.py behave' it says that the command is not recognised.
Therefore I believe that whilst I have added INSTALLED_APPS = ('behave_django',) to the local.py file it is not getting recognised. I have tried adding it outside the class and within. Is there a way I can run a script to check my list of installed_apps, etc. Also I am new to python and the configuration side has gotten me a bit confused.

You need to provide the --settings option so Django knows you wish to use a different settings file with your task
manage.py behave --settings=myapp.local

Related

Unable to fix error DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

Please help resolving this env issue/error. I did found many posts about resolving that error but I still couldn't fix mine. I guess I am just unable to understand it in the right way.
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I have just one app in my Django project, had created using django-admin startproject. The app is added to settings.py under INSTALLED_APPS, and all other settings are set to default by Django itself which i haven't modified.
I have few def in views.py working on models/forms, and those are working well.
I also have created a new folder (myscripts) in the project (next to the app-name folder), and in that myscripts folder i have my other py scripts (other than models/forms). Executing those scripts works, I am able to import those models/forms, it does some work and adds a new entry in django db sqlite3 correctly.
Further, i want to add/update execution status to the db entry (for a given pk/id) after my other scripts finishes its work.
To achieve that, I am trying a new py script which will import models to get its objects so i can update contents in the db but that fails. (throws me above error).
Based on other posts, i did try adding env variable DJANGO_SETTINGS_MODULE=my-app-name.settings, it doesn't work (i just have one app and django has it already configured -- i can see that in wsgi.py as os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my-app-name.settings') ).
I also tried code from django.conf import settings , but that also with no success.
However, when I run "python manage.py shell" and import models and its objects they don't throw error but thorws error when i run the update py script.
Please guide me where i can look for to fix the issue.

Running the Django REST framework quickstart tutorial

I'm new to python and didn't use django before. I want to run the Django REST framework quickstart tutorial so I can use it for testing another application (http://django-rest-framework.org/tutorial/quickstart.html).
I ran in two issues:
1) I'm confused at the "Settings" step, I don't know what file is the listing suposed to be in. (I pasted the contents in urls.py, then I tried with a settings.py in the same folder as the other files.)
2) Just before the "Testing our API" section, I don't know the command to launch the project. (I tried "python urls.py" because url has references to the other files.)
Thank you.
Before you start using the django-rest-framework, you may want to learn more about django itself, so try the django tutorial.
https://docs.djangoproject.com/en/dev/intro/tutorial01/
About your question: when you start a project in django, it contains a settings.py.
Inside this file you have to edit the INSTALLED_APPS Tuple adding 'rest_framework,' in the end of it (one line before ")") and putting
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'PAGINATE_BY': 10
}
in the end of the file.
To launch the project you have to sync the database first, so do python manage.py syncdb, and once you did this call python manage.py runserver
settings.py obviously
python manage.py runserver
urls.py is an important file that manages the mapping of urls to the executables, but it's not an entry point to the django. manage.py provides tons of functionality and even able to run development server for you. In short, read the manual :)

Heroku: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments

How do I use my production settings with heroku? This is my first attempt at any project deployment that I created ever, so I may be doing things completely wrong. I have a settings.py file and a settings_production file, but I can't seem to figure out how to get the production settings to work. I tried changing my manage.py from
"DJANGO_SETTINGS_MODULE", "myproject.settings"
to
"DJANGO_SETTINGS_MODULE", "myproject.settings_production"
then using the commands
git add .
git commit -m "production settings"
and I have also just tried changing DEBUG to False in my settings.py file. How do you commit changes to your settings in heroku or point to the correct file? I was able to get through the tutorial successfully, but I have not had luck trying to deploy my project. Also, should there be code that I add to manage.py that checks if it is a production or develop environment and uses the correct settings file accordingly, or do I manually change it? Still learning so I could be doing it completely wrong. Thanks for any help.
In Heroku, you can configure environment variables - they are called config vars.
The DJANGO_SETTINGS_MODULE environment variable should be set to myproject.settings_production.
Your manage.py is probably not being run in Heroku (there are other ways to run a Django app), which is why your change didn't work.

Unable to execute Django runserver and no suggested solution seems to work

I've run Django servers on localhost before and have never run into this problem. I'm desperately trying to figure out what I've done wrong.
I'm using Django 1.4 with Python 2.7 on Ubuntu 12.04.
As far as I can tell I've configured everything correctly - I'm actually using another functional Django project I built as a go-by.
If I run the following command (or any recommended variation thereof) I receive an error.
django-admin.py runserver localhost:8000
Here is the error:
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Can someone please enlighten me as to why this error is occurring, how to fix it and why it doesn't happen with my other Django project?!?
I've found many posts regarding this problem just by doing some quick Google searches, but none of the suggested solutions have helped - nor do I truly understand them.
I'm pretty sure you're supposed to run
manage.py runserver
from inside your project directory. It automatically loads your settings.py, etc.
From the Django docs:
Generally, when working on a single Django project, it’s easier to use manage.py. Use django-admin.py with DJANGO_SETTINGS_MODULE, or the --settings command line option, if you need to switch between multiple Django settings files
Providing some more code or examples of your directory structure might help.
First, the command is generally manage.py runserver 8000, so try that, and that make might a difference.
Second, in Django 1.4, the location of the settings.py file was moved. In previous versions of Django, the directory structure looked like this:
myproject/
settings.py
views.py
urls.py
myapp/
models.py
...
...
However, in Django 1.4, the main project settings and files were moved to a different directory:
myproject/
myproject/
settings.py
views.py
urls.py
myapp/
models.py
urls.py
...
...
So if you're using Django 1.4 but going off of previous examples, your settings.py might be in the wrong place. Additionally, I've found that when running django-admin.py startproject, it sometimes incorrectly creates two settings.py files, once in the old location and one in the new, which could be additionally confusing you. The only one that manage.py would pay attention to is the one in the project's directory.
If it turns out that your settings.py is in the wrong place but you don't want to move it, as your error suggests, you could set an environmental variable called DJANGO_SETTINGS_MODULE as the path to the Django settings.py you'd like to use for your project. I definitely don't recommend doing this.

App Engine problems using the command line

I am developing an App Engine project on Windows using Eclipse and Python 2.5 and Django 0.96. Everything in my app, including Django, is working nicely.
My problems arise when I try to use command line. For example, I'm told that if I want to clear the local datastore I can enter "python manage.py reset" but when I do so the response is "python: can't open file 'manage.py'".
I feel as if I have missed a configuration step. I have checked my system variables and "Path" includes "C:\Python25" (which I had added manually) but nothing Django or App Engine related. My .py extension is associated with C:\Python25\python.exe.
In my quest to solve this, and in trying to understand what manage.py is, I see that I might have had to create a Django project using "django-admin.py startproject [myproject]" but because everything works nicely from Eclipse I'm not sure if this is necessary now. In any case, if I try to enter this from the command line I get "'django-admin.py' is not recognized..."
Please, what am I missing?
If you're using Django 0.96 templates within a 'normal' App Engine app, then manage.py isn't involved at all.
/path/to/dev_appserver.py --clear_datastore .
is what you want, assuming you're CD'd to the root of your app.

Categories

Resources