Wednesday, January 27, 2016

Re: Django linking static content to dynamic content



On Wed, Jan 27, 2016 at 8:30 AM, Shekar Tippur <ctippur@gmail.com> wrote:
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


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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWc0buq7va3cGhc1xWnLK%3Dgrvh%3Dt_Jctfpo1DUx_ZPwnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment