Reputation: 143
The project name is project1 and I have one app in it - home. I'm making a navbar in the index.html. However, the first <li>
tag in the index.html gives me error and I'm not sure how to fix it.
home's urls.py
from django.conf.urls import url
from . import views
app_name = 'home'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^portfolio/$', views.portfolio, name='portfolio'),
url(r'^blog/$', views.blog, name='blog'),
url(r'^contact/$', views.contact, name='contact'),
]
home's views.py
def index(request):
return render(request, 'home/index.html')
home's index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Website</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'home/css/bootstrap.css' %}">
<link rel="stylesheet" href="{% static 'home/css/basic.css' %}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Pranav Gupta</a>
</div>
<ul class="nav navbar-nav">
{% url 'home' as home %}
<li {% if request.path == home %} class="active" {% endif %} ><a href="{% url 'home' %}">Home</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</nav>
Upvotes: 0
Views: 341
Reputation: 53669
home
is your application namespace. Your url is named index
.
You should use {% url 'home:index' %}
.
Upvotes: 1
Reputation: 4461
You dont have a url named home but you are setting it as {% url 'home' as home %}
Your root url is named index, change home to index.
Upvotes: 3