Не работает Django CSS
Новичок в Django. Есть файл index.html
:
<!DOCTYPE html>
{% load static %}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Django Level Two</title>
<link rel="stylesheet" href="{% static "css/mystyle.css" %}">
</head>
<body>
<h1>Hi welcome to Django Level Two!</h1>
<h2>Here are youre access records:</h2>
<div class="djangotwo">
{% if access_records %}
<table>
<thead>
<th>Site Names</th>
<th>Date Accessed</th>
</thead>
{% for acc in access_records %}
<tr>
<td>{{ acc.name }}</td>
<td>{{ acc.date }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>NO ACCESS RECORDS FOUND!</p>
{% endif %}
</div>
</body>
</html>
mystyle.css
:
h1{
color: red;
}
.djangotwo{
border: 2px solid black
}
views.py
:
from django.shortcuts import render
from django.http import HttpResponse
from first_app.models import Topic, Webpage, AccessRecord
def index(request):
webpages_list = AccessRecord.objects.order_by('date')
date_dict = {'access_records': webpages_list}
return render(request, 'first_app/index.html', context=date_dict)
Раньше index.html
просто выводил картинку и форматированый текст (картинку брал из папки static
). Сейчас изменил код чтобы выводил просто текст из файла populate_first_app.py
:
import os
import django
import random
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'first_project.settings')
django.setup()
from first_app.models import AccessRecord, Webpage, Topic
from faker import Faker
fakegen = Faker()
topics = ['Search', 'Social', 'Marketplace', 'News', 'Game']
def add_topic():
t = Topic.objects.get_or_create(top_name=random.choice(topics))[0]
t.save()
return t
def populate(N=5):
for entry in range(N):
# get the topic from the entry
top = add_topic()
# Create fake data for that entry
fake_url = fakegen.url()
fake_date = fakegen.date()
fake_name = fakegen.company()
# Create new webpage entry
webpg = Webpage.objects.get_or_create(topic=top, url=fake_url, name=fake_name)[0]
# Create a fake acces record for that webpage
acc_rec = AccessRecord.objects.get_or_create(name=webpg, date=fake_date)[0]
if __name__ == '__main__':
print('Populating scripts!')
populate(20)
print("Populating complete!")
Все работает. Но! При выводе все должно быть в таблице, но это не работает. Только красит h1
в красный цвет. Даже когда меняю цвет h1
ничего не меняеться. Долго шерстил свой код но ошибку найти не могу. Как это исправить?