403 Forbidden when trying to access static files on elasticbeanstalk - python

I have successfully deployed my application to Elastic beanstalk. Everything is working except the bootstrap themes. When I view source and try to access the links to the files I get.
Source
<!-- Custom CSS -->
<link href= "/static/css/blog-home.css" rel="stylesheet">
<link href= "/static/css/bootstrap-datetimepicker.css" rel="stylesheet">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
I get this...
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /static/bootstrap.min.css
on this server.<br />
</p>
</body></html>
Here is what I see in my logs
[authz_core:error] [pid 18657] [client 10.30.229.177:34675] AH01630: client denied by server configuration: /webapp, referer: http://www.evenster.io/user/user_id=2
I have configured the properties on EB to include the static folders in python.conf
option_settings:
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
I have also done a chmod -R 777 on my entire application tree to ensure that the files have permision.
My folder structure is:
app
├── __init__py.old
├── application.py
├── application.pyc
├── manage.py
├── migrations
│   ├── README
│   ├── alembic.ini
│   ├── env.py
│   ├── env.pyc
│   ├── script.py.mako
│   └── versions
│   ├── 48f38b800968_.py
│   └── 48f38b800968_.pyc
├── requirements.txt
└── webapp
├── __init__.py
├── __init__.pyc
├── _olddatabase.db
├── config.py
├── config.pyc
├── database.db
├── forms.py
├── forms.pyc
├── models.py
├── models.pyc
├── static
│   ├── blog-home.css
│   ├── bootstrap-datetimepicker.min.css
│   ├── bootstrap-theme.min.css
│   ├── css
│   │   ├── blog-home.css
│   │   ├── bootstrap-datetimepicker.min.css
│   │   ├── bootstrap-theme.css
│   │   ├── bootstrap-theme.css.map
│   │   ├── bootstrap-theme.min.css
│   │   ├── bootstrap-theme.min.css.map
│   │   ├── bootstrap.css
│   │   ├── bootstrap.css.map
│   │   ├── bootstrap.min.css
│   │   ├── bootstrap.min.css.map
│   │   ├── toolkit.css
│   │   └── toolkit.min.css
│   ├── fonts
│   │   ├── glyphicons-halflings-regular.eot
│   │   ├── glyphicons-halflings-regular.svg
│   │   ├── glyphicons-halflings-regular.ttf
│   │   ├── glyphicons-halflings-regular.woff
│   │   └── glyphicons-halflings-regular.woff2
│   └── js
│   ├── bootstrap-datetimepicker.min.js
│   ├── bootstrap.js
│   ├── bootstrap.min.js
│   ├── jquery.js
│   ├── moment-with-locales.min.js
│   ├── moment.js
│   ├── npm.js
│   ├── scripts.js
│   ├── toolkit.js
│   └── toolkit.min.js
├── templates
│   ├── 500.html
│   ├── _login.html
│   ├── _question_settings.html
│   ├── base.html
│   ├── create_event.html
│   ├── create_event2.html
│   ├── create_user.html
│   ├── event.html
│   ├── events.html
│   ├── flash.html
│   ├── index.html
│   ├── index2.html
│   ├── login.html
│   ├── logout.html
│   ├── question.html
│   ├── questions.html
│   ├── test.html
│   ├── user.html
│   ├── user_events.html
│   ├── user_questions.html
│   └── users.html
├── views.py
└── views.pyc

Related

NotSupportedError at / deterministic=True requires SQLite 3.8.3 or higher

I am trying to deploy a Django application using the default SQLite database to Elastic Beanstalk. The application works fine locally, however, on server, I get the error as :
Any idea what's wrong? Can we not deploy SQLite app on AWS EBS?
Here is my project structure that is getting deployed
├── .ebextensions
│   ├── django.config
├── app
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   ├── models.py
│   ├── static
│   │   └── app
│   │   ├── app.js
│   │   ├── logo.svg
│   │   └── style.css
│   ├── templates
│   │   └── app
│   │   ├── hello.html
│   │   ├── index.html
│   │   └── job_detail.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── db.sqlite3
├── env
│   ├── All Virtual env related files
├── images
│   ├── Photo_on_5-9-14_at_2.31_PM.jpg
│   ├── Photo_on_5-9-14_at_2.32_PM.jpg
│   └── Photo_on_5-9-14_at_2.32_PM_v4McLzE.jpg
├── myproject-test
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── requirements.txt
├── staticfiles
│   |-- All static files collected using collectstatic
│   ├── app
│   │   ├── app.js
│   │   ├── logo.svg
│   │   └── style.css
│   └── subscribe
│   ├── email-icon.png
│   ├── main.css
│   └── main.js
├── subscribe
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── form.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0002_subscribe_option_alter_subscribe_email_and_more.py
│   │   ├── 0003_alter_subscribe_option.py
│   ├── models.py
│   ├── static
│   │   └── subscribe
│   │   ├── email-icon.png
│   │   ├── main.css
│   │   └── main.js
│   ├── templates
│   │   └── subscribe
│   │   ├── subscribe.html
│   │   └── thank_you.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── templates
│   └── base.html
├── upload
│   └── images
│   ├── Photo_on_5-9-14_at_2.31_PM.jpg
│   └── Photo_on_5-9-14_at_2.31_PM_3.jpg
└── uploads
├── __init__.py
├── admin.py
├── apps.py
├── forms.py
├── images
│   └── Photo_on_5-9-14_at_2.31_PM_3.jpg
├── migrations
│   ├── 0001_initial.py
│   ├── 0002_uploadfile.py
│   ├── 0003_alter_uploadfile_file.py
│   ├── __init__.py
├── models.py
├── templates
│   └── uploads
│   ├── add_file.html
│   └── add_image.html
├── tests.py
├── urls.py
└── views.py
Deployment process:
Zip all the necessary files
Create AWS EBS application with Python
Add environment variables
Create app and access URL
Please help.

How can make django find a specific css file forSphinx?

I am using Sphinx to document my django application. My directory tree, based on this django tutorial is:
.
├── db.sqlite3
├── help
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── templates
│   │   └── help
│   │   ├── _images
│   │   ├── index.html
│   │   ├── _modules
│   │   ├── objects.inv
│   │   ├── _sources
│   │   │   └── index.rst.txt
│   │   └── _static
│   │   ├── css
│   │   │   ├── badge_only.css
│   │   │   └── theme.css
│   │   ├── fonts
│   │   └── js
│   │   ├── modernizr.min.js
│   │   └── theme.js
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── polls
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
└── users
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│   └── __init__.py
├── models.py
├── tests.py
├── urls.py
└── views.
The code to set the css file in the html is:
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
This looks like an relative link, but the css is not picked up when the help file is displayed in django.
views.py
def index(request):
return render(request, 'help/index.html', {})
urls.py
urlpatterns = [
url(r'^help/', views.index, name='index'),
]
It works if the page is loaded directly into the browser.
How can I get the css file loaded?
On the top of your html file specify:
{% load static %}
Your css:
<link rel="stylesheet" href="{% static 'css/theme.css' %}" type="text/css" />

Django template not found in main project directory error

I am getting a 'template not found' error, although I've set up a correct template hierarchy (or so I thought)
.
├── manage.py
├── twinja
│   ├── admin.py
│   ├── admin.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   └── views.py
└── twinjasite
├── __init__.py
├── __init__.pyc
├── settings.py
├── settings.py~
├── settings.pyc
├── static
│   └── twinja
│   ├── fonts
│   │   └── bootstrap
│   │   ├── glyphicons-halflings-regular.eot
│   │   ├── glyphicons-halflings-regular.svg
│   │   ├── glyphicons-halflings-regular.ttf
│   │   ├── glyphicons-halflings-regular.woff
│   │   └── glyphicons-halflings-regular.woff2
│   ├── images
│   ├── javascripts
│   │   ├── bootstrap
│   │   │   ├── affix.js
│   │   │   ├── alert.js
│   │   │   ├── button.js
│   │   │   ├── carousel.js
│   │   │   ├── collapse.js
│   │   │   ├── dropdown.js
│   │   │   ├── modal.js
│   │   │   ├── popover.js
│   │   │   ├── scrollspy.js
│   │   │   ├── tab.js
│   │   │   ├── tooltip.js
│   │   │   └── transition.js
│   │   ├── bootstrap.js
│   │   ├── bootstrap.min.js
│   │   └── bootstrap-sprockets.js
│   └── stylesheets
│   ├── framework.css
│   └── styles.css
├── templates
│   └── twinja
│   ├── base.html
│   └── menu.html
├── urls.py
├── urls.py~
├── urls.pyc
├── views.py
├── views.py~
├── views.pyc
├── wsgi.py
└── wsgi.pyc
At first I set up templates/base but that did not work. So I made it as you see here: templates/twinja/base
Ideally I'm setting up the MAIN template files which are independent of apps, which I thought was meant to go in the main folder (where settings.py is) but perhaps I am mistake.
Yes, I have 'twinja' set up in installed apps as well.
What appears to be wrong here?
TemplateDoesNotExist at /
twinja/base.html
If your template is independent of apps, it shouldn't be in your app folder - namespace it accordingly.
How do you load your template? Did you setup your templates/staticfolders in your settings.py?
Updated.
For the fresh project you need to configure your settings.py file. Read here, ask away if you still have a question.
Updated.
After you get familiar with static files and how to manage those, spend some time here.

Importing Static files to template with Django

I'm having trouble loading my CSS file into my HTML template. Below are the invovled files I'm working with. Can anyone see why the CSS wouldn't be loading?
settings.py
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
words.html
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'hello/words.css' %}" />
urls.py
urlpatterns = patterns('',
url(r'^
url(r'^Words', hello.views.index, name='index'),
url(r'^db', hello.views.db, name='db'),
url(r'^Add', hello.views.create, name='create'),
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns += staticfiles_urlpatterns()
words.css
.pri {
color: blue;
}, hello.views.index, name='index'),
Project Structure
murmurwall/
├── Procfile
├── README.md
├── hello
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── __init__.cpython-34.pyc
│   │   ├── admin.cpython-34.pyc
│   │   ├── forms.cpython-34.pyc
│   │   ├── models.cpython-34.pyc
│   │   └── views.cpython-34.pyc
│   ├── admin.py
│   ├── admin.pyc
│   ├── forms.py
│   ├── forms.pyc
│   ├── management
│   │   └── commands
│   │   ├── CSV
│   │   │   └── Pretty\ Little\ Liars.csv
│   │   ├── __pycache__
│   │   │   └── update_words.cpython-34.pyc
│   │   └── update_words.py
│   ├── models.py
│   ├── models.pyc
│   ├── static
│   │   └── hello
│   │   └── words.css
│   ├── templates
│   │   ├── add_word.html
│   │   ├── base.html
│   │   ├── db.html
│   │   └── words.html
│   ├── tests.py
│   ├── views.py
│   └── views.pyc
├── manage.py
├── murmurwall
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── __init__.cpython-34.pyc
│   │   ├── settings.cpython-34.pyc
│   │   ├── urls.cpython-34.pyc
│   │   └── wsgi.cpython-34.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── static
│   │   └── humans.txt
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── requirements.txt
├── runtime.txt
└── staticfiles
├── admin
│   ├── css
│   │   ├── base.css
│   │   ├── changelists.css
│   │   ├── dashboard.css
│   │   ├── forms.css
│   │   ├── ie.css
│   │   ├── login.css
│   │   ├── rtl.css
│   │   └── widgets.css
│   ├── img
│   │   ├── changelist-bg.gif
│   │   ├── changelist-bg_rtl.gif
│   │   ├── default-bg-reverse.gif
│   │   ├── default-bg.gif
│   │   ├── deleted-overlay.gif
│   │   ├── gis
│   │   │   ├── move_vertex_off.png
│   │   │   └── move_vertex_on.png
│   │   ├── icon-no.gif
│   │   ├── icon-unknown.gif
│   │   ├── icon-yes.gif
│   │   ├── icon_addlink.gif
│   │   ├── icon_alert.gif
│   │   ├── icon_calendar.gif
│   │   ├── icon_changelink.gif
│   │   ├── icon_clock.gif
│   │   ├── icon_deletelink.gif
│   │   ├── icon_error.gif
│   │   ├── icon_searchbox.png
│   │   ├── icon_success.gif
│   │   ├── inline-delete-8bit.png
│   │   ├── inline-delete.png
│   │   ├── inline-restore-8bit.png
│   │   ├── inline-restore.png
│   │   ├── inline-splitter-bg.gif
│   │   ├── nav-bg-grabber.gif
│   │   ├── nav-bg-reverse.gif
│   │   ├── nav-bg-selected.gif
│   │   ├── nav-bg.gif
│   │   ├── selector-icons.gif
│   │   ├── selector-search.gif
│   │   ├── sorting-icons.gif
│   │   ├── tooltag-add.png
│   │   └── tooltag-arrowright.png
│   └── js
│   ├── LICENSE-JQUERY.txt
│   ├── SelectBox.js
│   ├── SelectFilter2.js
│   ├── actions.js
│   ├── actions.min.js
│   ├── admin
│   │   ├── DateTimeShortcuts.js
│   │   └── RelatedObjectLookups.js
│   ├── calendar.js
│   ├── collapse.js
│   ├── collapse.min.js
│   ├── core.js
│   ├── inlines.js
│   ├── inlines.min.js
│   ├── jquery.init.js
│   ├── jquery.js
│   ├── jquery.min.js
│   ├── prepopulate.js
│   ├── prepopulate.min.js
│   ├── timeparse.js
│   └── urlify.js
├── hello
│   └── words.css
└── humans.txt
Your STATIC_ROOT = 'staticfiles' need to be the absolute path to the static files. For example STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/")). This might have to be changed for deployment. An example i use for openshift:
if 'OPENSHIFT_REPO_DIR' in os.environ:
STATIC_ROOT = os.path.join(os.environ.get('OPENSHIFT_REPO_DIR'), 'wsgi', 'static')
else:
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))
See also django static static url static root

Django: Application labels aren't unique

I have been working on the issue of duplicate labels in Django and from this answer I have added the following files to my "jobs" project folder:
jobs/apps.py
# jobs/apps.py
from django.apps import AppConfig
class JobsConfig(AppConfig):
name = 'jobs'
verbose_name = "jobs2"
jobs/init.py
# jobs/__init__.py
default_app_config = 'jobs.apps.JobsConfig'
This hasn't really helped much and I still get the error when trying syncdb:
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: jobs
Also, changing from "name = 'jobs'" to "name = 'jobs2'" just gives me the error:
ImportError: No module named jobs2
File Structure
/opt/Webapp
├── userfiles
├── templates
│   └── admin
│   └── base.html
├── static
│   ├── admin_tools
│   │   ├── images
│   │   │   └── apto.gif
│   │   └── css
│   │   └── theming.css
│   └── admin
│   └── css
│   └── base.css
├── smartrecruitment
│   ├── wsgi.py
│   ├── urls.py
│   ├── settings.pyc
│   ├── settings.py
│   ├── __init__.pyc
│   └── __init__.py
├── requirements.txt
├── manage.py
├── jobs
│   ├── views.py
│   ├── urls.py
│   ├── tests.py
│   ├── testhelpers.py
│   ├── templates
│   │   └── jobs
│   │   ├── test.html
│   │   ├── success.html
│   │   ├── registration.html
│   │   ├── registrationcomplete.html
│   │   └── application.html
│   ├── tables.py
│   ├── static
│   │   └── jobs
│   │   ├── styles
│   │   │   ├── index.css
│   │   │   ├── hide_admin_original.css
│   │   │   └── application.css
│   │   ├── style.css
│   │   └── images
│   │   └── apto.gif
│   ├── models.py
│   ├── migrations
│   │   ├── __init__.py
│   │   ├── 0002_auto__del_field_registrant_name__add_field_registrant_first_name__add_.py
│   │   └── 0001_initial.py
│   ├── lists.py
│   ├── __init__.pyc
│   ├── __init__.py
│   ├── forms.py
│   ├── apps.pyc
│   ├── apps.py
│   └── admin.py
├── fileuploads
│   ├── tests.py
│   ├── templates
│   │   └── fileuploads
│   │   ├── index.html
│   │   ├── details.html
│   │   ├── base.html
│   │   └── add.html
│   ├── models.pyc
│   ├── models.py
│   ├── __init__.pyc
│   ├── __init__.py
│   ├── forms.pyc
│   ├── forms.py
│   ├── context_processors.py
│   └── admin.pyc
├── dashboard.pyc
└── dashboard.py
You have a mix of old-style (south: 0002_auto_del...) and new-style (django: 0001_initial) migrations in your jobs app. Easiest fix would be to delete all numbered migrations rm jobs/migrations/0???_*.py* and recreate migrations by running manage.py makemigrations

Categories