2

I want to add bootstrap template in my django app. I have downloaded it and kept in my static folder, then added its path in setting.py file as:

STATIC_URL = '/static/'

index.html of template is:

{% load staticfiles %}

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>Business Casual - Start Bootstrap Theme</title>

<!-- Bootstrap Core CSS -->

<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">

<!-- Custom CSS -->
<link href="{% static 'css/business-casual.css' %}" rel="stylesheet">

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700,100italic,300italic,400italic,600italic,700italic" rel="stylesheet" type="text/css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<div class="brand">Business Casual</div>
<div class="address-bar">3481 Melrose Place | Beverly Hills, CA 90210 

...

but doesn't working ,please help me

3
  • I would suggest installing and using this package django-bootstrap3. It is Django optimized, easy to use and has good documentation. django-bootstrap3.readthedocs.io/en/latest/index.html Commented Apr 12, 2018 at 11:12
  • How exactly is it not working, do you get an error message? Commented Apr 12, 2018 at 11:13
  • css and bootstrap doesn't work Commented Apr 12, 2018 at 11:31

1 Answer 1

2

if you're running this from python manage.py runserver you'll need to include the following in your urls.py

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

If you're running it in production make sure you've run python manage.py collectstatic

You'll also need the following in settings.py, replacing project with your app

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "project/static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Sign up to request clarification or add additional context in comments.

1 Comment

If you have 'django.contrib.staticfiles' in your INSTALLED_APPS you don't need to add to urlpatterns. It will work on the development server with debug on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.