Jump to content


Photo

About the static file path

static

  • Please log in to reply
2 replies to this topic

#1 sopython

sopython

    Newbie

  • Members
  • 8 posts

Posted 12 April 2019 - 09:52 PM

I want to use a static file. So I create a static folder under the project folder and put the file under the static folder. And I also added the needed info in settings.py, url.py and the html. But it still doesn't work. Is the something wrong in my files? Or there is something which need the admin's configure?

 

What have been added in settings.py:

 

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

... ...

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected')
 
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
  ]

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder"

 

*****************************************************************************

What added in url.py:

 

from django.conf.urls.static import static

 

**************************************************

What added in html:

 

{% load static %}

 

background-image: url("{% static "pyStocks/imgs/background-cloth.png"%}");

 

 



#2 Krydos

Krydos

    Rank X Member

  • Root Admin
  • 17,959 posts
  • Gender:Male

Posted 14 April 2019 - 12:42 AM

Did you add an exception for the static directory in your .htaccess?

#3 sopython

sopython

    Newbie

  • Members
  • 8 posts

Posted 15 April 2019 - 03:30 AM

Oh, yes, that's the reason. It works after adding the exception. Thanks!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users