如何配置网络服务器将特定页面作为默认页面?
我正在使用 Lighttpd 和 Django。我已将 Lighttpd 服务器配置为将所有以“.psp”扩展名结尾的请求传递给 Django。
我的启动页面是通过 Django 提供的页面,访问方式为“http://192.168.1.198/home.psp”。我想让用户浏览此页面,而无需在网址中显式写入“home.psp”,即使用“http://192.168.1.198”
这可能吗?
感谢您提前提供的任何帮助。
I am using Lighttpd and Django. I have configured my Lighttpd server to pass all the requests ending with ".psp" extension to Django.
My startup page is a page served through Django, which is accessed as "http://192.168.1.198/home.psp". I want to enable the user to browse this page without writing "home.psp" explicitly in the url i.e. using "http://192.168.1.198"
Is this possible?
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您在这里混淆了“旧”方法之间的概念,即让单个文件代表网页,这些网页本身包含在响应 django/frameworks 如何工作之前传递给解释器的代码。
如果您熟悉 apache,可以想象 django 承担了 mod_rewrite 的部分角色。 Django 和其他框架具有所谓的调度程序或路由机制。
基本上,他们遵循 MVC 模式,即应该将模型、控制器和视图分开(用 django 的说法是模型、模板和视图)。
现在,你在 django 中有一个名为 urls.py 的文件,其中包含路由(url)和方法名称的列表(通常包含在views.py 中) )来处理它们。这是一个例子:
这里
testapp
是一个 python 包,views.py
是一个 python 文件,index
是一个 django 视图。该 url 是由正则表达式构造的,因此我可以将任何我想要的内容作为 url,就像 stackoverflow url 的形成方式一样。所以基本上,您再也不需要文件扩展名了。我强烈建议你买一本关于 django 的好书——周围有几本。
I think you're confusing concepts here between the "old" method of having individual files represent web pages which themselves contain code that is passed off to an interpreter before being sent in a response to how django/frameworks work.
If you're familiar with apache, imagine django as in part taking on the role of mod_rewrite. Django, and other frameworks, have what's called a dispatcher, or routing, mechanism.
Basically, they subscribe to the MVC pattern that says you should separate out the model, controller and view (in django parlance, model, template and view).
Now what then happens is you have a file called
urls.py
in django, which contains a list of routes (urls) and names of methods (usually contained inviews.py
) which handle them. Here's an example:Here
testapp
is a python package,views.py
is a python file andindex
is a django view. The url is constructed from regex, so I can have whatever I want as the url, much how stackoverflow urls are formed.So basically, you never need file extensions again. I'd strongly suggest getting a good book on django - there are a few around.
您可能正在寻找的是 index-file.names Lighty 的配置文件中的指令。只需将“home.psp”添加到配置文件的列表中,当未指定文件名时,Lighty 就会查找它。
What you might be looking for is the index-file.names directive in Lighty's configuration file. Just add "home.psp" to the list in your configuration file, and Lighty will look for it when no filename is specified.
我自己解决了这个问题。这就是我所做的:
我必须在lighttpd配置文件的
url.rewrite-once
块中添加一条语句,例如:除此之外,我在urls.py中添加了以下行:
希望这有帮助未来的某个人。谢谢楼上大家的回复。干杯!
I solved the problem myself. Here is what I did:
I had to add a statement inside
url.rewrite-once
block of lighttpd's configuration file like:Apart from this, I added the following line in my urls.py:
Hope this helps someone in the future. Thanks everybody for your replies above. Cheers!