使用 CGI 的模板架构

发布于 2024-07-10 04:58:15 字数 184 浏览 7 评论 0原文

我有一个网页需要显示 sqlite 数据库。 现在我正在通过 CGI 动态创建整个页面。 但是,我宁愿有一个 html 文件,然后用数据库内容填充该文件中的一个表。 最好的方法是什么? 我仅限于使用 C 语言编写 html、javascript 和 CGI​​。

非常感谢任何帮助。

谢谢! 汤姆

I have a web page that needs to display a sqlite database. Right now i am creating the entire page dynamically through CGI. However, I would rather have one html file and just populate a table within the file with the database content. What is the best method to do that? I am limited to html, javascript and CGI in C.

Any help is greatly appreiated.

Thanks!
Tom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莫言歌 2024-07-17 04:58:15

如果您的内容每天(或每小时等)更新一次,那么您可以通过 cron 将 C 代码安排为独立应用程序来运行。 它读入“header”html 模板文件,从数据库生成表格,然后复制“footer”html 模板文件。 生成的文件被复制到您想要的 Web 服务器位置,然后 Web 服务器可以简单地提供 HTML 文件。

如果您没有 cron,您可以将 C 移动到 CGI C 代码中,您可以通过“隐藏”URL 手动调用该代码,以相同的方式生成 HTML 文件。

如果表一直更新,那么只需执行上述操作,但将数据返回给用户,而不是创建一个文件来静态服务。

我假设您无权访问任何类型的服务器端包含(嵌入式 Web 服务器?)。

If your content is updated once a day (or hour, etc) then you could schedule the C code as a standalone application via cron to run. It reads in a "header" html template file, generated the table from the database, then copies the "footer" html template file. This generated file gets copied to the web server location you want it, then the webserver can simply serve the HTML file.

If you have no cron, you could move the C into a CGI C code that you can call manually via a "hidden" URL that generates the HTML file in the same way.

If the table updates all the time, then just do the above but return the data to the user rather than creating a file to serve statically.

I assume you don't have access to server-side includes of any sort (embedded web server?).

呆° 2024-07-17 04:58:15

你有多少这样的工作? 你的 sqlite 连接在你的 C 代码中工作吗? 编写一个普通的 CGI 应用程序并不困难,只需输出标头,尤其是 Content-Type,最好是 Content-Length(如果您知道的话),然后输出页面。

对于模板系统,您可以编写html文件并用动态内容替换某些标签。 看看 Smarty 等一些模板系统也许能获得一些灵感。

How much of this do you have working? Do you have your sqlite connection working in your C code? Writing a plain CGI app isn't difficult, just output your headers, especially Content-Type and preferably Content-Length(if you know it), and then just output the page.

As for a templating system, you can write html files and replace certain tags with the dynamic content. Take a look at some templating systems like Smarty for some inspiration perhaps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文