[英]How do I write to an HTML file using expressjs
Ok, this sounds crazy, but let me explain.好的,这听起来很疯狂,但让我解释一下。 I want a user to be able to push a button, and then the html file is edited in such a way that it a NEW p element is created, and stays there PERMENENTLY (eg on reload and for EVERYONE to see).
我希望用户能够按下一个按钮,然后编辑 html 文件,以便创建一个新的 p 元素,并永久保留在那里(例如重新加载并让每个人都看到)。 Any way on how I could do that.
关于我如何做到这一点的任何方式。
Again I am using node.js/express, and html/js/css.我再次使用 node.js/express 和 html/js/css。
It really depends upon exactly what you're doing.这真的取决于你在做什么。
Conceptually, you would probably use some sort of template system for generating your HTML files (like Jade, Dust, EJS, Handlebars, Nunjucks, PUG, etc..) and then you store some state in a database and use a query from the database as input to the template whenever you render a particular page.从概念上讲,您可能会使用某种模板系统来生成 HTML 文件(如 Jade、Dust、EJS、Handlebars、Nunjucks、PUG 等),然后将一些 state 存储在数据库中并使用数据库中的查询每当您呈现特定页面时作为模板的输入。
So, when you add an item to the database, it will show up in all future renders of the page.因此,当您将项目添加到数据库时,它将显示在页面的所有未来呈现中。
So, your button would trigger a form post to your server which would add an item to the database and the response from the form post would be a rendering of the page after adding the item to the database.因此,您的按钮将触发一个表单发布到您的服务器,这会将一个项目添加到数据库中,并且表单发布的响应将是在将项目添加到数据库后呈现页面。 All future renders of the page from all users would also show those same items in the rendered page.
所有用户将来对页面的所有呈现也将在呈现的页面中显示这些相同的项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.