我的主页加载正常,但是当我单击一个应该将我带到index.html的按钮时,我收到下面发布的错误。当在本地运行时,它工作正常,但是当部署到 AWS(EC2,使用 nginx 和 Gunicorn)时,它不起作用并给出以下错误。我刚开始使用 django 和 AWS,如有任何反馈,我们将不胜感激。
Request Method: GET
Request URL: http://18.222.182.68/index.html
Using the URLconf defined in LectureLingo.urls, Django tried these URL patterns, in this order:
[name='index']
admin/
The current path, index.html, didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
def index_view(request):
return render(request, 'index.html')
from django.urls import path
from . import views
urlpatterns = [
path('', views.index_view, name='home'),
path('index/', views.index_view, name='index'),
]
from django.conf.urls import include
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('', include('transcript.urls')),
path('admin/', admin.site.urls),
]
{% load static %}<!DOCTYPE html>
<html>
<head>
<title>Chat</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="{% static 'indexstyles.css' %}">
</head>
<body>
<p id="status">Connection status will go here</p>
<div class="custom-tooltip" style="display:none;"></div>
<p id="transcript"></p>
<script src="{% static 'IndexJS.js' %}"></script>
</body>
</html>
{% load static %}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'homestyles.css' %}">
<title>Home Page</title>
</head>
<body>
<div class="text">LectureLingo</div>
<div class="container">
<div class="dropdown-container">
<div class="dropdown-label">
<div class="label">Translate from:</div>
<select class="dropdown" id="dropdown1" required>
<option value="" disabled selected hidden>Select...</option>
<option value="cs">Czech</option>
</select>
</div>
<div class="dropdown-label">
<div class="label">Translate To:</div>
<select class="dropdown" id="dropdown2" required>
<option value="" disabled selected hidden>Select...</option>
<option value="af">Afrikaans</option>
</select>
</div>
</div>
<button id="sendButton" onclick="checkDropdowns()">Start</button>
</div>
<script src="{% static 'homeJS.js' %}"></script>
</body>
</html>
document.querySelector('#sendButton').onclick = function() {
// Check if both dropdowns have selections
var dropdownFrom = document.getElementById('dropdown1').value;
var dropdownTo = document.getElementById('dropdown2').value;
if (dropdownFrom !== "" && dropdownTo !== "") {
// Send data through WebSocket
websocket.send(JSON.stringify({
'dropdown1': dropdownFrom,
'dropdown2': dropdownTo
}));
localStorage.setItem('detectedLanguage', dropdownTo);
window.location.href = 'index.html';
} else {
alert('Please select options from both dropdowns.');
}
};
我的代码的问题是我在应该是
index.html
时请求了index/
。我不断更新,但始终没有解决问题。
那是因为我的网络浏览器正在缓存我的文件,所以我所做的任何更改都没有得到反映。通过在边缘和镀铬上执行
ctr + f5
可以轻松修复此问题。