我正在嘗試創建一個 webapp,在 localhost:8000 我想在主頁上放置一個顯示學校資料集的表格。問題是 css 樣式不適用于 localhost:8000,而是發生在 localhost:63342 上。
本地主機:63342
- 樣式修改可見(參見 GID 單元格)
- 資料庫不加載

本地主機:8000
- 風格看不出來
- 資料庫負載

我也希望能夠在 localhost:8000 上看到樣式修改
schooldetails.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="schooldetails.css">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Document</title>
<style>
th,td{
border: 1px black solid;
}
</style>
</head>
<body>
<h1>School Page</h1>
{% if schools %}
<table>
<tr id="school-gap ">
<th class="cell">GID</th>
<th>Type</th>
<th>Province</th>
<th>Street</th>
<th>House_number</th>
<th>Postcode</th>
<th>City</th>
<th>Municipality</th>
<th>Geometry</th>
</tr>
<tr>
{% for st in schools %}
<td>{{st.gid}}</td>
<td>{{st.schooltype}}</td>
<td>{{st.provincie}}</td>
<td>{{st.straatnaam}}</td>
<td>{{st.huisnummer}}</td>
<td>{{st.postcode}}</td>
<td>{{st.plaatsnaam}}</td>
<td>{{st.gemeentena}}</td>
<td>{{st.geom}}</td>
</tr>
{% endfor %}
</table>
{% else %}
<h1>No Data</h1>
{% endif %}
</body>
</html>
學校詳情.css
/* (A) CONTAINER */
#school-gap {
/* (A1) GRID LAYOUT */
display: grid;
/* (A2) SPECIFY COLUMNS */
grid-template-columns: auto auto auto;
/* we can also specify exact pixels, percentage, repeat
grid-template-columns: 50px 100px 150px;
grid-template-columns: 25% 50% 25%;
grid-template-columns: 100px 20% auto;
grid-template-columns: repeat(3, auto); */
}
/* (B) GRID CELLS */
th.cell {
background: #fff600;
border: 1px solid #000;
padding: 10px;
}
/* (C) RESPONSIVE - 1 COLUMN ON SMALL SCREENS */
@media screen and (max-width: 640px) {
#grid-col { grid-template-columns: 100%; }
}
視圖.py:
from django.http import JsonResponse
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.parsers import JSONParser
from rest_framework.decorators import api_view
from base.models import RSchools as School
from definitions import ROOT_DIR
from .serializers import SchoolSerializer
@api_view(['GET'])
def get_data(request):
schools = School.objects.all()
return render(request, f'{ROOT_DIR}/templates/schooldetails.html', {'schools': schools})
uj5u.com熱心網友回復:
問題是pycharm找不到css檔案。我更改了以下內容并使其作業:
設定.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, '/')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
schooldetails.html:
<link rel="stylesheet" href="static/css/schooldetails.css">
'''
uj5u.com熱心網友回復:
在您的 settings.py 檔案中,取消允許的主機 ass 這個:
ALLOWED_HOSTS = ['localhost', 'localhost:8000']
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/468350.html
