How to make my css files to work in django

后端 未结 2 463
深忆病人
深忆病人 2021-01-21 05:36

I am new to django but have some relative skills in python. I just started building a project in django and so far I have been able to create an app within my project. Also, I h

2条回答
  •  星月不相逢
    2021-01-21 06:04

    Just a small demo for very basic css/img usage with the development-server: python manage.py runserver. You should not use this for production. For the user input/output you should have a look at the tutorial.

    filestructure

    project
      |- static
      |   |- css
      |   |   |- stuff.css
      |- media
      |   |- images
      |   |   |- love.jpg
      |- templates
      |- urls.py
      |- __init__.py
      |- manage.py
      |- settings.py
    

    base.html

    
    
       
    
    
       

    I like django!

    settings.py

    TEMPLATE_CONTEXT_PROCESSORS = (
        'django.contrib.auth.context_processors.auth',
        'django.core.context_processors.debug',
        'django.core.context_processors.i18n',
        'django.core.context_processors.media',
        'django.core.context_processors.static',
        'django.core.context_processors.request',
        'django.contrib.messages.context_processors.messages',
    )
    
    STATIC_URL = '/static/'
    MEDIA_URL = '/media/'
    

    urls.py

    # example windows
    (r'^media/(?P.*)$', 'django.views.static.serve',
            {'document_root': 'C:/python25/lib/site-packages/project/media/', 'show_indexes': True}),
    # example *ix
    (r'^static/(?P.*)$', 'django.views.static.serve',
            {'document_root': '/usr/lib/python25/site-packages/project/static/', 'show_indexes': True}),
    

提交回复
热议问题