Maxsteel Maxsteel - 2 years ago 120
Python Question

Bootstrap template with Django

I have a complete skeleton of a website in Bootstrap 3. I am very new to Django (not to Python though). I want to integrate this particular theme and build the backend using Django. I cannot find any website for instructions on this. How can this be done? Any help is appreciated.

Answer Source

You just need to prepare your templates that you do usually.In your settings file, make the following changes.

    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(PROJECT_BASE_PATH, 'templates').replace('\\', '/'),

# List of callables that know how to import templates from various sources.

STATIC_URL = '/static/'

MEDIA_URL = 'media/'



Change your file to include the urls for static files. Like this:

urlpatterns = patterns('',

    url(r'^$',LandingPage.as_view(),name='home'),)+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Place your templates in a templates folder inside your app/project and all the css, js and images inside static folder. Be sure to to include {{STATIC_URL}} before all css,js and image urls inside all the templates. Something like this:

<script src="{{STATIC_URL}}js/jquery.js"></script>

For more information on handling templates in django, try this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download