Hi, I have been learning python3 over the past year and have progressed onto learning Django. I am attempting the project Django Djitney, Writing More Views | Codecademy
I have completed the step to create the lines views:
from django.shortcuts import render
from .models import Line, Station, Stop
from .forms import StopForm, LineForm, StationForm
# Add your imports below:
from django.views.generic import TemplateView, ListView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
class HomeView(TemplateView):
template_name = "routes/home.html"
def get_context_data(self):
context = super().get_context_data()
context["lines"] = Line.objects.all()
context["stations"] = Station.objects.all()
context["stops"] = Stop.objects.all()
return context
# Create your views here.
class LinesView(ListView):
model = Line
template_name = "routes/lines.html"
class CreateLineView(CreateView):
model = Line
template_name = "routes/add_line.html"
form_class = LineForm
class UpdateLineView(UpdateView):
model = Line
template_name = "routes/update_line.html"
form_class = LineForm
class DeleteLineView(DeleteView):
model = Line
template_name = "routes/delete_line.html"
success_url = "/lines"
and created the paths in urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
path('lines/', views.LinesView.as_view(), name='lines'),
path('lines/new/', views.CreateLineView.as_view(), name='create_line'),
path('lines/<pk>/update/', view.UpdateLineView.as_view(), name='update_line'),
path('lines/<pk>/delete/', views.DeleteLineView.as_view(), name='delete_line'),
]
I have also uncommented the Lines link is base.html:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
rel="shortcut icon"
type="image/x-icon"
href="https://www.codecademy.com/favicon.ico"
/>
<link
rel="stylesheet"
type="text/css"
href="{% static 'routes/style.css' %}"
/>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Oxygen:wght@300;400;700&display=swap"
rel="stylesheet"
/>
<title>{% block title %}Django Djitney{% endblock %}</title>
{% block head %}{% endblock %}
</head>
<body>
<div class="app">
<header>
<div class="header-first-row">
<img
src="{% static 'routes/djitney.png' %}"
alt="Django Djitney Logo"
width="80px"
/>
<h1 class="title">Django Djitney</h1>
</div>
<nav class="navbar">
<a class="nav-item" href="{% url 'home' %}">Home</a>
<a class="nav-item" href="{% url 'lines' %}">Lines</a>
{% comment %} <a class="nav-item" href="{% url 'stations' %}">Stations</a> {% endcomment %}
{% comment %} <a class="nav-item" href="{% url 'stops' %}">Stops</a> {% endcomment %}
</nav>
</header>
<main>{% block content %}{% endblock %}</main>
</div>
</body>
</html>
When I run this code the built in browser displays a white screen and I cant find any errors in the code. Have I missed somethng?
Any help much appreciated