I'm sure this is an issue on my end but I can't figure out why Django is throwing an ImportError for db_file_storage.urls within my application's main urlpatterns (MyApp/urls.py). I've followed the configuration setup from here https://django-db-file-storage.readthedocs.io/en/master/ and I have the rest of the setup complete, I just can't seem to get past this Import issue.
When testing using the Django shell from CLI I am able to import 'db_file_storage.urls' fine and inspect the object. It's only when accessing the application from the browser does the Import fail to resolve and throws an error. I also tested importing db_file_storage at the top of my urls.py which was successful. Any attempts to include urls from db_file_storage resulted in the same Import error.
ImportError at /
No module named 'db_file_storage.urls'
Request Method: | GET
Request URL: https://myapp.internalsite.com/
Django Version: 2.0.1
Exception Type: ImportError
Exception Value: No module named 'db_file_storage.urls'
Exception Location: <frozen importlib._bootstrap> in _find_and_load_unlocked, line 2224
Python Executable /usr/bin/python3
Python Version: 3.4.9
Python Path: ['/opt/MyProject',
'/opt/virtual-env/lib64/python34.zip',
'/opt/virtual-env/lib64/python3.4',
'/opt/virtual-env/lib64/python3.4/plat-linux',
'/opt/virtual-env/lib64/python3.4/lib-dynload',
'/usr/lib64/python3.4',
'/usr/lib/python3.4',
'/opt/virtual-env/lib/python3.4/site-packages']
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('', include('reports.urls')),
path('admin/', admin.site.urls),
path('findings/', include('findings.urls')),
path('reports/',include('reports.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('files/', include('db_file_storage.urls')),
] + static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
import db_file_storage
urlpatterns = [
path('', include('reports.urls')),
path('admin/', admin.site.urls),
path('findings/', include('findings.urls')),
path('reports/',include('reports.urls')),
path('accounts/', include('django.contrib.auth.urls')),
# path('files/', include('db_file_storage.urls')),
] + static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_seo_js',
'findings',
'reports',
'sslserver',
'widget_tweaks',
'guardian',
'db_file_storage',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
MIDDLEWARE_CLASSES = (
'django_seo_js.middleware.EscapedFragmentMiddleware', # If you're using #!
'django_seo_js.middleware.UserAgentMiddleware', # If you want to detect by user agent
)
ROOT_URLCONF = 'myproject.urls'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # this is default
'guardian.backends.ObjectPermissionBackend',
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
'django.template.context_processors.static',
],
},
},
]
WSGI_APPLICATION = 'myproject.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '****',
'USER': '****',
'PASSWORD': '******',
'HOST': '******',
'PORT': 5432
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
DEFAULT_FILE_STORAGE = 'db_file_storage.storage.DatabaseFileStorage'
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
IncludeOptional conf.d/*.conf
Alias /media/ /opt/MyProject/media/
Alias /static/ /opt/MyProject/myproject/static/
<Directory /opt/MyProject/myproject/static>
Require all granted
</Directory>
<Directory /opt/MyProject/media>
Require all granted
</Directory>
WSGIScriptAlias / /opt/MyProject/myproject/wsgi.py
LoadModule wsgi_module /opt/virtual-env/lib/python3.4/site-packages/mod_wsgi/server/mod_wsgi-py34.cpython-34m.so
WSGIDaemonProcess MyProject python-home=/opt/virtual-env/ python-path=/opt/MyProject:/opt/virtual-env/lib/python3.4/site-packages socket-user=nobody
WSGIProcessGroup MyProject
WSGISocketPrefix /var/run/wsgi
<Directory /opt/MyProject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>