Python 角度服务工作,角度构建不更新文件

Python 角度服务工作,角度构建不更新文件,python,django,angular,ng-build,Python,Django,Angular,Ng Build,我正在运行一个带有角度前端和Django后端的项目。今天,当我更改模板中的一些代码时,ng构建没有更新。我发现它既不更新模板更改,也不更新组件更改。但是,当我运行ng serve并转到127.0.0.1:4200而不是Django端口8000时,将呈现新的更新版本 我的设置方式是Django使用TemplateViev指向一个模板: {% load static %} {% csrf_token %} <!doctype html> <html lang="en"> &l

我正在运行一个带有角度前端和Django后端的项目。今天,当我更改模板中的一些代码时,ng构建没有更新。我发现它既不更新模板更改,也不更新组件更改。但是,当我运行ng serve并转到127.0.0.1:4200而不是Django端口8000时,将呈现新的更新版本

我的设置方式是Django使用TemplateViev指向一个模板:

{% load static %}
{% csrf_token %}
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>AngularWebapp</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
  <app-root></app-root>
{% block javascript %}
<script type="text/javascript" src="{% static 'runtime.js' %}"></script><script type="text/javascript" src="{% static 'polyfills.js' %}"></script><script type="text/javascript" src="{% static 'styles.js' %}"></script><script type="text/javascript" src="{% static 'vendor.js' %}"></script><script type="text/javascript" src="{% static 'main.js' %}"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
{% endblock %}
</body>
</html>
和url.py:

from django.contrib import admin
from django.urls import path, re_path, include
from django.views.generic import TemplateView
from rest_framework import routers
from authentication.views import AccountViewSet, LoginView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib.staticfiles import views

router=routers.SimpleRouter()
router.register('accounts', AccountViewSet)

class IndexView(TemplateView):
    template_name = 'index.html'

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/', include(router.urls)),
    re_path(r'^api/v1/auth/login/$', LoginView.as_view(), name='login'),
    re_path(r'^.*/$', IndexView.as_view()),
    path('', IndexView.as_view()),
]
这是我唯一拥有静态文件的地方,也是存放ng build文件的地方,也就是说,静态加载从ng build时输出的文件夹加载runtime.js等

但是,从昨天开始,我对angular webapp/src/app文件夹中的应用程序所做的更改在生成时不会得到更新。我尝试删除dist文件夹以创建一个新文件夹,但这并没有改变任何事情。当它回来,我运行项目时,它仍然以某种方式使用旧的布局,而ng serve工作得非常完美


我想知道的是ng build是如何工作的吗?

这可能是一个缓存破坏问题:您的文件仍然具有相同的名称,并且由于浏览器缓存了这些文件,因此不会重新加载它们

考虑使用
--prod
标志进行构建,该标志包含其他几个标志,如
--aot
,但要纠正您的问题,请尝试使用
--output hashing=all
进行构建

直接从
ng build--help

--output-hashing=none|all|media|bundles 
  (String) Define the output filename cache-busting hashing mode.
  aliases: -oh <value>, --outputHashing <value>
——输出哈希=none | all | media | bundle
(字符串)定义输出文件名缓存破坏哈希模式。
别名:-哦,--输出

我觉得自己太愚蠢了,在盯着我的代码看了这么久之后,清除浏览器缓存完全解决了这个问题。这个解决方案是为了“自动清除缓存”,不要指望你的用户自己清除缓存!可以通过使用cntrl+shift+r重新加载来解决。这将执行强制重新加载,而不从缓存加载。
--output-hashing=none|all|media|bundles 
  (String) Define the output filename cache-busting hashing mode.
  aliases: -oh <value>, --outputHashing <value>