页面未找到(404)请求方法:GET 请求网址:http://18.222.182.68/index.html 使用定义的URL配置

0 投票
1 回答
37 浏览
提问于 2025-04-14 18:12

我的主页加载得很好,但当我点击一个按钮,想要跳转到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.

views.py代码

def index_view(request):
    return render(request, 'index.html')

urls.py代码

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index_view, name='home'),
    path('index/', views.index_view, name='index'),
]

主urls.py代码

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),
]

index.html代码

{% 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>

主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>

主Javascript(只有按钮):

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.');
        }
    };

1 个回答

0

我代码的问题在于,我请求的是 index.html,其实应该是 index/。我一直在更新这个,但问题始终没有解决。

原因是我的网页浏览器在缓存我的文件,所以我做的任何更改都没有显示出来。这个问题可以通过在 Edge 和 Chrome 浏览器中按 ctr + f5 来轻松解决。

撰写回答