Next JS is loading external script but not executing them - javascript

In my next app with the latest version 12.1.6, I'm trying to use bootstrap. I've added bootstrap CSS and js files from CDN to the head of pages/_app.js as below,
import '../styles/globals.css'
import Head from 'next/head';
function MyApp({ Component, pageProps }) {
return (
<>
<Head>
<meta charset="UTF-8"/>
<meta name="keywords" content="Ogani, unica, creative, html"/>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</Head>
<Component {...pageProps} />
</>
);
}
export default MyApp
I used bootstrap Nav as below,
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarTogglerDemo03">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"/>
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
I've noticed bootstrap CSS is loaded and executing. But its JS is loading but not executing. Because the page isn't interactive menu isn't expanding and collapsing on click. Can anyone tell me what's a problem with it?

import Head from 'next/head';
const Layout = (props) => (
<div>
<Head>
{/* import external javascript */}
<script type="text/javascript" src="..."></script>
<script type="text/javascript" src="/js/myscript.js"></script>
</Head>
<p id="demo"></p>
</div>
);
export default Layout;

The error was occurring because React/Next DOM operations were colliding with Jquery DOM operations. By deferring the jquery operations after react/next it worked. Just used useEffct hook to do jquery. It's solved here.
Replace the IIFE in mainW.js for:
// of course you perhaps want better names
function _runJQueryControls($) {
// rest of function
}
window.runJQueryControls = () => _runJQueryControls(jQuery);
Inside index.js
useEffect(() => {
window?.runJQueryControls();
}, []);
In next.config.js
/** #type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: false,
};
special thanks to icyJoseph who helped.

Related

How to import header to all pages of HTML [duplicate]

This question already has an answer here:
How can I reuse HTML code across several HTML files
(1 answer)
Closed 28 days ago.
I have header HTML page and I want to implement this header to all other HTML pages. Can I do it using HTML or JS? without PHP.
I am a beginner in web programming and I made a simple frontend website using HTML and CSS.
header.html code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<title>White Aim</title>
</head>
<body>
<div id="header">
<nav class="navbar navbar-expand-lg" >
<div class="container-fluid">
<a class="navbar-brand" href="index.html">
<img class="logo-style" src="assests/logo.svg" alt="White Aim">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mb-2 mb-lg-0 navbar-text">
<li class="nav-item mx-2">
<a class="nav-link active" aria-current="page" href="index.html">الصفحة الرئيسية</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="about-us.html">نبذة عنا</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="our-experience.html">خبرتنا</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="contact-us.html">تواصل معنا</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="profile.html">الملف التعريفي</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</body>
</html>
You could save the header code inside a global javascript variable and then render it with insertAdjacentHTML()
JS:
const header = `
<div id="header">
<nav class="navbar navbar-expand-lg" >
<div class="container-fluid">
<a class="navbar-brand" href="index.html">
<img class="logo-style" src="assests/logo.svg" alt="White Aim">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mb-2 mb-lg-0 navbar-text">
<li class="nav-item mx-2">
<a class="nav-link active" aria-current="page" href="index.html">الصفحة الرئيسية</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="about-us.html">نبذة عنا</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="our-experience.html">خبرتنا</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="contact-us.html">تواصل معنا</a>
</li>
<li class="nav-item mx-2">
<a class="nav-link" href="profile.html">الملف التعريفي</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
`;
document.addEventListener('DOMContentLoaded', (event) => {
const homepage = document.querySelector('.homepage');
homepage.insertAdjacentHTML('afterbegin', header);
});
<body class="homepage">
<!-- CONTENT -->
<script src="script.js"></script>
</body>
This way you could render your header variable in all the html files in which you include the script.js.
Keep in mind that this is probably not a best practice, there are better ways to create HTML components, however this will do what you need using just vanilla JS without using external libraries or PHP.
The better way would be to use a php include. This lets the server do the include which saves a round trip.
<?php include 'footer.php';?>
It is also possible to import/include via Javascript on page load per what you asked (you asked for a non php solution). However it will cause another round trip to the server and unnecessarily slow your website down. I don't recommend it, but if you do want to go that route you can look at the Javascript script below based on https://www.w3schools.com/howto/howto_html_include.asp:
html:
<div w3-include-html="content.html"></div>
js:
function includeHTML() {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.querySelectorAll("[w3-include-html]");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {elmnt.innerHTML = this.responseText;}
if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
/* Exit the function: */
return;
}
}
}
At the bottom of the page:
<script>
includeHTML();
</script>
You could also opt for a build step (preprocessing) at author time using a templating language. This makes things a bit more complex for a beginner, it is somewhat similar to writing php. But in contrast to php the html is assembled before the website is requested by users, al work is done before it is put online.
Some preprocessing languages are pug, ERB, haml, twig, ... here's a feature overview: https://css-tricks.com/comparing-html-preprocessor-features/
I don't use it but I know Adobe Dreamweaver has also a feature where you can include html snippets. It then builds the html with the included snippets which you can put online. But I don't recommend Dreamweaver.

My toggler is not working. I have tried placing js cdn in top and bottom both but didn't work [duplicate]

This question already has answers here:
How to add hamburger menu in bootstrap
(3 answers)
Closed 2 months ago.
I tried placing the js cdn in top and it did not work. I was trying to make my navbar responsive and used toggler. The navbar became responsive but the toggler button is not working.
Here is my code, the hamburger menu is not working:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TinDog</title>
<!-- Latest compiled and minified CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Latest compiled JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<section id="title">
<!-- Nav Bar -->
<nav class="navbar bg-dark navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="">Tindog</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="NssavbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Download</a>
</li>
</ul>
</div>
</nav>
</section>
</body>
</html>
For Bootstrap V5 it's data-bs-toggle not data-toggle, plus you needed a "#" to point the target to an ID not a class. Lastly you had a typo "NssavbarSupportedContent" should be "navbarSupportedContent".
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TinDog</title>
<!-- Latest compiled and minified CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Latest compiled JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<section id="title">
<!-- Nav Bar -->
<nav class="navbar bg-dark navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="">Tindog</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">Download</a>
</li>
</ul>
</div>
</nav>
</section>
</body>
</html>

Bootstrap collapse responsive navbar closes back after opening it when on small screen

The navbar works fine on the big screen but when you go to a mobile screen the collapse closes back after pressing the collapse icon.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body style="background-color: #7e9094;">
<nav style="background-color: #213239;" class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand active" href="index.html">Home</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" data-target="#demo" id="navbarText">
<ul class="navbar-nav" id="demo">
<li class="nav-item">
<a class="nav-link" href="shop/shop.html">Shop</a>
</li>
<li class="nav-item">
<a class="nav-link" href="projects/projects.html">Projects</a>
</li>
</ul>
<span class="navbar-text"><a class="nav-link" href="index.html"><img style="float: right;" width="10%" src="img/image.img"></a></span>
</div>
</nav>
</body>
</html>
Just update the CDN link for your JavaScript to match the CSS. Both need to be on the 4.x version.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body style="background-color: #7e9094;">
<nav style="background-color: #213239;" class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand active" href="index.html">Home</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" data-target="#demo" id="navbarText">
<ul class="navbar-nav" id="demo">
<li class="nav-item">
<a class="nav-link" href="shop/shop.html">Shop</a>
</li>
<li class="nav-item">
<a class="nav-link" href="projects/projects.html">Projects</a>
</li>
</ul>
<span class="navbar-text"><a class="nav-link" href="index.html"><img style="float: right;" width="10%" src="img/image.img"></a></span>
</div>
</nav>
</body>
</html>
it is just a supplement to the answer of #isherwood and #MrUpsidown.
Indeed, you have incompatible css, jquery and bootstrap versions in your code.
If you want to use the latest version of Bootstrap, you should do like in an example from the answer above. It means you need the same version of css as the version of bootstrap is, 4.3.1. It is also recommended to use jquery slim build. You could read more on the 'Getting started' guide for Bootstrap 4.3.
If you actually need the bootstrap 3.4.1 (that actually was a typo in your code, I believe), you need different css and jquery for it as it follows from the 'Getting started' guide for Bootstrap 3.4 An example of navbar for that version of bootstrap you can find here.
In this case your code will be something like this:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body style="background-color: #7e9094;">
<nav style="background-color: #213239;" class="navbar navbar-expand-lg navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbarText"
aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Home</a>
</div>
<div class="collapse navbar-collapse" data-target="#demo" id="navbarText">
<ul class="navbar-nav" id="demo">
<li class="nav-item">
<a class="nav-link" href="shop/shop.html">Shop</a>
</li>
<li class="nav-item">
<a class="nav-link" href="projects/projects.html">Projects</a>
</li>
</ul>
<span class="navbar-text">
<a class="nav-link" href="index.html"><img style="float: right;" width="10%" src="img/image.img"></a>
</span>
</div>
</nav>
</body>
</html>
But be careful. 3.4.1 and 4.3.1 are actually different versions :) Good luck with that!

Bootstrap 4 JavaScript not working Symfony4

I'm trying to use Bootstrap 4 in Symfony 4 using yarn package manager but somehow the JavaScript is not working. I have no errors in the console but when I try to trigger the navbar collapsed button I won't open the navbar.
This is my code:
app.js
var $ = require('jquery');
require("bootstrap/js/dist/");
base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="stylesheet" href="{{ asset('build/css/app.css') }}">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">CRM Fabriek</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
{% block body %}{% endblock %}
<script src="{{ asset('build/js/app.js') }}"></script>
</body>
</html>
I compiled the js to the build/js/app.js file by using yarn run encore dev
Import Bootstrap’s JavaScript by adding this line to your app’s entry point (usually index.js or app.js):
import 'bootstrap';
or indicate the path completely
import 'bootstrap/dist/js/bootstrap';
or if you prefer require()
require('bootstrap/dist/js/bootstrap');
Alternatively, you may import plugins individually as needed:
import 'bootstrap/js/dist/util';
import 'bootstrap/js/dist/dropdown';
...
https://getbootstrap.com/docs/4.1/getting-started/webpack/#importing-javascript
In the webpack-encore documentation says that you must in your webpack.config.js file add a call .autoProvidejQuery() because Bootstrap expects jQuery to be available as a global variable.
// webpack.config.js
Encore
// ...
.autoProvidejQuery();
http://symfony.com/doc/current/frontend/encore/bootstrap.html#importing-bootstrap-javascript

bootstrap navbar dropdowns not showing with django

I'm trying to add twitter-bootstrap to a django project. I've got a html file called base.html which acts as a wrapper file for other html code which is placed inside of it before it gets send back in the HttpResponse.
base.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="{% static '/css/bootstrap.min.css' %}" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src = "{% static '/js/bootstrap.min.js' %}"></script>
<title>TITLE</title>
</head>
<body>
{% autoescape off %}{{ content }}{% endautoescape %}
</body>
</html>
This file is the only file which will ever get send back to the visitor of the webside so I would imagine that if I add the files bootstrap needs inside base.html that it would work also on the code in content. Infact, all the css stuff seems to work fine but whenever I try to open a dropdown menu in the navbar of my site, it does not show up.
This is the source code of the page that has difficulties:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src = "/static/js/bootstrap.min.js"></script>
<title>TITLE</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="?p=index">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="?p=channel">testchannel</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<form class="form-inline">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Username
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="?p=Channel">Visit Channel</a>
<a class="dropdown-item disabled" href="#">Statistics</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item disabled" href="#">Settings</a>
</div>
</li>
</ul>
</div>
</nav>
<h1>A TEST HEADER</h1>
</body>
</html>
Clicking on the "/static/css/bootstrap.min.css" or "/static/js/bootstrap.min.js" both redirects me to a file (no 404 error pops up).
what could be the problem causing the navbar to not work? How can I fix it?
EDIT:
As requested the settings.py part that handles static:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# some more stuff here like INSTALLED_APPS and TEMPLATES
STATICFILES_DIRS = (
'/home/<name>/Desktop/django/myproject/Bootstrap',
)
STATIC_URL = '/static/'
Please make sure you have included the correct static path in the settings.py file.
I have used something like the following in one of my project and it works fine.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)

Categories

Resources