Question

I not sure how to include css to my html. I have an app in my project that has it's own template folder. I want to get the sample.css into my html.

Something in the lines of <link rel="stylesheet" type="text/css" href="{% %}">

Not really sure what to put in between {% %}

structure:

/proj
   /app
      /templates
         sample.css
         sample.html

Here is my template_dirs:

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,'templates'),
    os.path.join(BASE_DIR,'home/templates'),
    os.path.join(BASE_DIR,'gallery/templates'),
    os.path.join(BASE_DIR,'contact/templates'),
    os.path.join(BASE_DIR,'aboutme/templates'),
)

If any other info is required. Please let me know!

updated struture

/proj
   /app
      /static
         /css
            sample.css
      /templates
         sample.html
Was it helpful?

Solution

css files, as well as js files and images, are considered static files.

The usual approach is to use django.contrib.staticfiles built-in django app to manage static files.

If you set up the app correctly this is how your link would look like:

<link rel="stylesheet" type="text/css" href="{% static 'sample.css' %}">

OTHER TIPS

as @alecxe mentions, have them in a folder named static and include these in your settings file.

STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top