简体   繁体   English

你如何在 HTML 中引用 a.ejs 文件

[英]How do you href a .ejs file in HTML

I'm trying to build a login system with Nodejs and express.我正在尝试使用 Nodejs 和 express 构建登录系统。 I have a login page with the login forms using ejs.我有一个使用 ejs 登录 forms 的登录页面。

In my index.html file there's a button that's supposed to direct the user to that login page:在我的index.html文件中,有一个按钮可以将用户引导到该登录页面:

 <button id="loginBtn"> <a href="views/login.ejs"><LI> LOGIN </LI></a> </button>

but it prints the ejs code of the login page instead of displaying the actual page.但它会打印登录页面的 ejs 代码,而不是显示实际页面。 Anyone know what I'm doing worng?有人知道我在做什么吗?

To render a view, you only specify an endpoint in expressjs and call only that end point要渲染视图,您只需在 expressjs 中指定一个端点并仅调用该端点

You should not try to call the .ejs file location您不应该尝试调用.ejs文件位置

Example: in this code login.ejs will automatically render behind the scene, the server library will do it, res.render('login') will automatically call login.ejs例子:这段代码login.ejs会在后台自动渲染,服务端库会做, res.render('login')会自动调用login.ejs

 router.get('/home', function(req, res, next) {
    res.render('login');
 });

You hyperlink should be calling the router mapping endpoint alone您的超链接应该单独调用路由器映射端点

 <a href="/home"><li> LOGIN </li></a>

once you decided using EJS, for UI designing purpose, if the UI designing part alone is given to you, then you can do a dummy code to render one EJS with fixed data, you don't have to run the entire website with DB一旦你决定使用 EJS 来进行 UI 设计,如果只给你 UI 设计部分,那么你可以做一个虚拟代码来渲染一个具有固定数据的 EJS,你不必用 DB 运行整个网站

For example: there a data which is assumed which will render a EJS, to render with dummy data you can do this例如:假设有一个数据将呈现 EJS,要使用虚拟数据呈现,您可以这样做

Get the data from the developer who is doing his part and do this code从正在尽其本分的开发人员那里获取数据并执行此代码

 router.get('/home', function(req, res, next) {
    var data = {"name": "Emmanuel"}
    res.render('login', data);
 });

as you can see the data is directly coded temporary如您所见,数据是直接temporary编码的

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

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