Error: No module named fileupload - django

I'm attempting to use this ported version of jQuery File Upload (https://github.com/sigurdga/django-jquery-file-upload). I placed the 'fileupload' directory in the root of the project (next my myapp, settings.py) and modified my urls.py file with url(r'^upload/', include('fileupload.urls')), and added 'fileupload', to my INSTALLED_APPS setting in my settings.py file. When I try python manage.py validate (OR shell OR syncdb) I get this error: Error: No module named fileupload
Did I install the application wrong? I have PIL installed and obviously Django (1.4.1).

If you're using Django 1.4, and you've installed the fileupload app in the same directory as the settings.py, then you probably need to use the path myproject.fileupload instead of fileupload.
# settings.py
INSTALLED_APPS = (
...
'myproject.fileupload',
...
)
# urls.py
url(r'^upload/', include('fileupload.urls'))
The alternative would be to move your fileupload app into the parent directory.

Related

django wsgi setup with settings subfolder

I'm trying differents environment settings for my project, below is my project folder structure:
|-app
|-project
|-__init__.py
|-settings
|-__init__.p
|-base.py
|-dev.py
|-prod.py
|-urls.py
|-wsgi.py
In base.py, how can i setup WSGI_APPLICATION django settings variable to point wsgi file on parent folder ?
File wsgi.py:
if base.STATUS == 'DEV':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings.dev')
application = get_wsgi_application()
elif base.STATUS == 'PROD':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings.prod')
application = Cling(get_wsgi_application())
else:
raise Exception('Settings App Error !')
File base.py:
...
WSGI_APPLICATION = 'project.wsgi.application'
...
File dev:
from project.settings.base import *
ALLOWED_HOSTS = ['127.0.0.1']
DEBUG = TRUE
File prod.py:
from project.settings.base import *
ALLOWED_HOSTS = ['domain']
DEBUG = FALSE
The error is:
django.core.exceptions.ImproperlyConfigured: WSGI application 'project.wsgi.application' could not be loaded; Error importing module.
Thanks in advance.
Your WSGI file is named wsgy.py, but Django expects wsgi.py. Rename the file to wsgi.py.
You need to have an __init__.py file in your project folder to import your project folder as a module. Just make an empty __init__.py file in the project directory.
SOLVED
The differents configuration environments are ok the problem was with a library dependency:
The requirements.py file was:
django-static
instead of:
dj-static
The strange is the error thrown was:
django.core.exceptions.ImproperlyConfigured
instead of:
ModuleNotFoundError

How to add a sub-app in django to INSTALLED_APPS?

I have the structure of my project:
project
———— project
———— app
———————— subapp
———— manage.py
I added my sub-app to INSTALLED_APPS like that:
INSTALLED_APPS = ['app.apps.AppConfig', 'app.subapp.apps.SubapConfig']
But it doesn't works. Django gives me an error message:
No module named 'news' and Cannot import 'news'. Check that
'apps.subapp.apps.SubapConfig.name' is correct.
Let's assume I've created an app named polls with the following command:
python manage.py startapp polls
Now I want to create a sub-app named subpoll inside the main app means inside the polls folder. So, how do I do that?
At first, I'll create a directory My_App_Name inside the /polls folder. In my case, I'll create a subpoll folder inside the polls folder.
After that, run the following command to create the new app.
python manage.py startapp My_App_Name ./polls/Your_Apps_Folder_Name/
So, in my case the following command will be like:
python manage.py startapp subpoll ./polls/subpoll/
Finally, I'll add just created apps name in the settings.py like below:
INSTALLED_APPS = [
...,
'polls',
'polls.subpoll',
]
I had a similar issue. In the apps.py Config class you need to set name to be the full dotted path. So based on the structure you give:
project
———— project
———— app
———————— subapp
———— manage.py
You would have:
class AppConfig(AppConfig):
name = "app"
and
class SubappConfig(AppConfig):
name = "app.subapp"
This should then work for you.

Scrapy project can't find django.core.management

I'm trying to follow the method here to 'Scrapy' data from the web and simultaneously save that data directly to my Django database using Scrapy's item pipeline.
However, when I try to run scrapy crawl spidername, I'm getting the error:
ImportError: No module named django.core.management
At first I thought it was because my Scrapy project was outside of my Django project folder, but even after I moved the whole project into my Django project folder I kept getting the same error. If I open a python shell inside the Scrapy project folder in its new location (inside my Django project folder), import django.core.management works fine. So what's going on?
EDIT: Some additional info: I'm doing this on a Webfaction server, and the path to my Django project is /home/gchorn/webapps/django_app/django_project. I'm using Django version 1.4.1, Scrapy 0.16 and Python2.7. The layout of the Django+Scrapy project is as follows:
django_project/
__init__.py
manage.py
settings.py
urls.py
myproject #folder containing wsgi.py
app1
app2
app3
templates
ScrapyProject/
scrapy.cfg
ScrapyProject/
__init__.py
items.py
pipelines.py
settings.py
spiders/
__init__.py
my_spider.py
Try setting this in your Spider's settings.py:
import os
import sys
sys.path.append('/home/gchorn/webapps/django_app')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
Then you can import your model classes like:
from django_project.app1.models import some_model

ImportError After Moving App to Nested Folder

My application was working fine when I wanted to see whether I could organize my project in a better way. I read through this tutorial on structuring a django project.
Before my project structure was as follows:
camucamu
books
admin.py
models.py
views.py
__init__.py
static
templates
urls.py
views.py
settings.py
wsgi.py
__init__.py
What I wanted to do was move the books app into an apps folder. Thus I did that and changed the project structure to the following:
camucamu
apps
books
admin.py
models.py
views.py
__init__.py
static
templates
urls.py
views.py
settings.py
wsgi.py
__init__.py
I then changed the imports in views.py and admin.py
from books.models to apps.books.models.
I also changed INSTALLED_APPS in settings.py from books to apps.books.
When I then tried to run syncdb, I get the following error:
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError apps.books: No module named apps.books
What am I messing up here so it can't find my app anymore?
Your apps folder does not have an __init__.py file so it cannot be recognized as a python module
I got the same error, following the same guide, as the last point of the following list was not cited. Make sure you performed the following changes:
Create a blank __init__.py file inside the apps folder (needed for python to recognize it as a package)
Update the import statements wherever you refer to an external app:
from projectname.apps.appname.models import YourModel, YourOtherModel
Inside settings.py edit INSTALLED_APPS such that it looks like this:
INSTALLED_APPS = (
...
# apps
'projectname.apps.appname1',
'projectname.apps.appname2',
)
This one is not specified in the guide: In all your urls.py files, update the urlpatterns!
BEFORE:
# client views
urlpatterns += patterns('appname',
...
)
AFTER:
# client views
urlpatterns += patterns('projectname.apps.appname',
...
)
Finally remember to update your changes by calling python manage.py syncdb
Hope that helped.

Django uwsgi import error

I have a Django project with one app called subscribe. In root urls.py I use include from subscribe's urls.py.
I put to INSTALLED_APPS subscribe and in subscribe's urls.py I use subscribe.views.<name> for call my views. When server run as python manage.py runserver locally all works fine. But when server run on nginx+uwsgi with virtualenv, I've got ImportError: No module named subscribe.
When I changing subscribe to project.subscribe in INSTALLED_APPS and in subscribe's urls.py changing subscribe.views.<name> to project.subscribe.views.<name> all works fine.
uwsgi config:
[uwsgi]
socket = 127.0.0.1:9003
workers = 2
master = true
virtualenv = /home/user/python
chdir = /home/user
env = DJANGO_SETTINGS_MODULE=project.settings
module = django.core.handlers.wsgi:WSGIHandler()
daemonize = /home/user/uwsgi.log
Why should I use absolute path import and how I can change it to relative back on nginx+uwsgi with virtualenv?
Your uwsgi config should include pythonpath=/path/where/lives/settings.py/ directive, so python interpreter will know where to find your apps.
Find more information about uwsgi config options:
http://projects.unbit.it/uwsgi/wiki/Doc
http://projects.unbit.it/uwsgi/wiki/Example