Django linking static content to dynamic content

68 views
Skip to first unread message

Shekar Tippur

unread,
Jan 27, 2016, 11:30:02 AM1/27/16
to Django users
Hello,

I have implemented authentication via django allauth. I am trying to link UI which is loosely coupled with django.
I am able to get to the index page by all other static content throes a 404 error. Appreciate any help on this.
I have gone thro https://docs.djangoproject.com/en/1.8/howto/static-files/ but I guess I am missing something.

Here is what I have tried:

1. I have copied all my html code to templates folder

2. Created symbolic links to the location of my static files under BASE_DIR

3. Here is my settings.py

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',
],
},
},
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "templates/static"),
os.path.join(BASE_DIR, "css"),
os.path.join(BASE_DIR, "img"),
os.path.join(BASE_DIR, "js"),
)

- S


James Schneider

unread,
Jan 27, 2016, 2:40:10 PM1/27/16
to django...@googlegroups.com
Kind of an odd layout that you have specified. A tree listing of this structure with just the directories would be helpful.

Is this an issue with the built-in dev server, or are you trying to put this into production? 

Can you add a print(STATICFILES_DIRS) at the end of your settings.py file and see what the dev server prints out? Those paths should line up with where your static files are.

I'm also not sure if the static files helpers included in Django will follow symlinks. Make sure that the user where the server process is being run (be it the dev server or a production server) has proper read access to those files and directories.

Are you running python manage.py collectstatic? You probably won't need to for the development server, but will for a production server.

-James

Shekar Tippur

unread,
Jan 27, 2016, 3:47:28 PM1/27/16
to Django users
James,

Thanks for responding. This is just my development env. I have tried running collectstatic as well. I have included static file helpers.
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

print(STATICFILE_DIRS):
('/Users/ctippur/PycharmProjects/trainer/templates/static', '/Users/ctippur/PycharmProjects/trainer/templates/css', '/Users/ctippur/PycharmProjects/trainer/templates/img', '/Users/ctippur/PycharmProjects/trainer/templates/js')
This is being run on local laptop. I have permissions to run this.

Here my tree listing.

├── __pycache__

│   └── manage.cpython-34.pyc

├── create_static

├── db.sqlite3

├── manage.py

├── static

│   ├── tools

├── templates

│   ├── applayout.html

 |    |── fonts -> static/tools/DEVELOPER/HTML_version/fonts

 |    |── img -> static/tools/DEVELOPER/HTML_version/img

 |    |── css -> static/tools/DEVELOPER/HTML_version/css

 |    |── js -> static/tools/DEVELOPER/HTML_version/fonts

 |    |── xml -> static/tools/DEVELOPER/HTML_version/fonts

│   ├── base.html

│   ├── blank_.html

│   ├── blog.html

│   ├── bootstrap-forms.html

│   ├── bootstrap-validator.html

│   ├── buttons.html

│   ├── calendar.html

│   ├── chartjs.html

│   ├── chat.html

│   ├── ckeditor.html

│   ├── datatables.html

│   ├── difver.html

│   ├── dropzone.html

│   ├── dygraphs.html

│   ├── email-template.html

│   ├── error404.html

│   ├── error500.html

│   ├── fa.html

│   ├── flags.html

│   ├── flot.html

│   ├── forgotpassword.html

│   ├── form-elements.html

│   ├── form-templates.html

│   ├── forum-post.html

│   ├── forum-topic.html

│   ├── forum.html

│   ├── gallery.html

│   ├── general-elements.html

│   ├── glyph.html

│   ├── gmap-xml.html

│   ├── grid.html

│   ├── image-editor.html

│   ├── inbox.html

│   ├── index.html

│   ├── index_ie8_prototype.html

│   ├── inline-charts.html

│   ├── invoice.html

│   ├── jqgrid.html

│   ├── jqui.html

│   ├── lock.html

│   ├── login.html

│   ├── morris.html

│   ├── nestable-list.html

│   ├── other-editors.html

│   ├── plugins.html

│   ├── pricing-table.html

│   ├── profile.html

│   ├── projects.html

│   ├── register.html

│   ├── registration

│   ├── search.html

│   ├── static

│   ├── table.html

│   ├── timeline.html

│   ├── treeview.html

│   ├── typography.html

│   ├── validation.html

│   ├── widgets.html

│   └── wizard.html

├── trainer

│   ├── __init__.py

│   ├── __pycache__

│   ├── models.py

│   ├── serializers.py

│   ├── settings.py

│   ├── urls.py

│   ├── views

│   ├── views.py

│   └── wsgi.py

└── urls.py

Reply all
Reply to author
Forward
0 new messages