【问题标题】:Django React -- Deployment Error On Heroku (Page not found 404)Django React -- Heroku 上的部署错误(找不到页面 404)
【发布时间】:2020-02-17 06:32:39
【问题描述】:

我正在将我的 Django React 项目部署到 Heroku。构建成功,但是当我访问https://django-react-app-nba.herokuapp.com/ 的站点时,我得到了django-react-app-nba.herokuapp.com/:14 GET https://django-react-app-nba.herokuapp.com/static/frontend/main.js net::ERR_ABORTED 404 (Not Found)

(本项目开发遵循本教程https://www.valentinog.com/blog/drf/#Django_REST_with_React_Django_and_React_together

ServerError (GET https://django-react-app-nba.herokuapp.com/static/frontend/main.js net::ERR_ABORTED 404 (Not Found))

我不明白为什么 Django 甚至在寻找这个 URL,谁能启发我?

我的项目文件路径

nbavoting urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("frontend.urls")),
    path("", include("teams.urls")),
    path("", include("users.urls")),
]

前端 urls.py

from django.urls import path
from . import views

urlpatterns = [path("", views.index)]

前端视图.py

from django.shortcuts import render

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

我对这个问题的猜测是前端的路由器与服务器端的路由冲突? (我在 React 中使用 HashRouter)

【问题讨论】:

  • 请发布您的代码而不是图片

标签: django reactjs heroku webpack package.json


【解决方案1】:

你忘了运行“npm run build”:D

【讨论】:

    【解决方案2】:

    我忘了运行“npm run build”...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 2020-12-28
      • 2018-09-12
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 2020-10-25
      相关资源
      最近更新 更多