简体   繁体   English

仅使用 static 文件加载页面的特定部分

[英]Loading only specific portion of page with static files

I am trying to make a single app website.我正在尝试制作一个应用程序网站。 Each page on the site includes the header which contains the static files that are reused over and over throughout the site like jQuery for example.该站点上的每个页面都包含 header,其中包含 static 文件,这些文件在整个站点中一遍又一遍地重复使用,例如 jQuery。 When a user goes on the main page for example, all static files are loaded for the site and for that specific page.例如,当用户进入主页时,将为站点和该特定页面加载所有 static 文件。 Let's say the user wants to go to a new link.假设用户想要 go 到一个新链接。 What I'd like to do is update the content of that page without loading the full page (again this next page will contain the header, which is already loaded).我想做的是在不加载整个页面的情况下更新该页面的内容(同样,下一页将包含已加载的 header)。 An example sketch looks like this:示例草图如下所示:

{% extends 'core/base.html' %}  //This is the header file (contains base static files)
{% block styles %}
    {% load static %}
    <link href="{% static 'core/profile.css' %}?v1" rel="stylesheet" type="text/css">
{% endblock %}

{% block content %}
..actual content...
{% endblock %}
  <script>
     ...inline javascript specific to page only...
  </script>

I'd like to load the actual content.我想加载实际内容。 I can do that by just finding the class within this HTML page and appending it to the current page.我可以通过在此 HTML 页面中找到 class 并将其附加到当前页面来做到这一点。 However, the static for that specific page won't get loaded.但是,不会加载该特定页面的 static。 That is my current problem right now.这是我现在的问题。 How do I get the static files loaded along with portion that I want loaded?如何获取 static 文件以及我想要加载的部分? How do I also load the specific JavaScript specific to that page only (Script tags at the bottom).如何仅加载特定于该页面的特定 JavaScript(底部的脚本标签)。

My current solution is just creating a new page and removing the {% extends 'core/base.html' %} , but this defeats the purpose of doing things only once.我目前的解决方案只是创建一个新页面并删除{% extends 'core/base.html' %} ,但这违背了只做一次的目的。 I don't want to update 2 pages each time there's an update.我不想每次有更新时都更新 2 页。 Is there a better way to do what I'm trying to achieve?有没有更好的方法来做我想要实现的目标?

you need to have 1 global js file and then update html elements with id or class name like other js library... try onload="myFunction()"您需要有 1 个全局 js 文件,然后像其他 js 库一样使用 id 或 class 名称更新 html 元素...尝试onload="myFunction()"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM