在所有应用程序中实施站点前缀

发布于 2024-08-17 07:52:02 字数 475 浏览 2 评论 0原文

我正在 Google 的 App Engine 上开发一个应用程序,其中一个功能是通过 Facebook Connect 进行身份验证。我已经完成了所有设置并达到了一定的水平,但为了在我的开发机器上进行测试,我在一台面向公众的服务器上创建了一个反向代理,该服务器代理到开发机器。

除了大多数链接没有我为代理创建的前缀之外,一切都工作正常。

因此,这让我思考,是否有一种简单的方法来创建站点范围的应用程序前缀,该前缀不仅适用于我的应用程序,还适用于我想使用的任何第三方应用程序?

是否有一些我可以包含的中间件或者我没有读过的 Django 文档?

**更新:** 在下面的评论之后,我想到的前缀位于域名和应用程序网址之间:

http://example.com/PREFIX/myapp/view/

I'm in the middle of developing an app on Google's App Engine, and one of the features is auth via Facebook Connect. I've got everything set up and working up to a certain level, but in order to test it against my dev machine, I've created a reverse proxy on one of my public facing servers that proxies through to the dev machine.

It all works fine except for most of the links are without the prefix I've created for the proxy.

So that got me thinking, is there an easy way to create a site-wide app prefix that not only works with my apps, but any 3rd party ones I want to use?

Is there some middleware I can include or a peice of the Django docs I've not read?

**Update: ** Following the comment below, the prefix I'm thinking of goes in between then the domain name and the app url:

http://example.com/PREFIX/myapp/view/

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

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

发布评论

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

评论(2

小巷里的女流氓 2024-08-24 07:52:02

myapp 的 URL 设计为独立的(以便其 URL 可以“包含”在另一个项目的 URL 中)。

urlpatterns = patterns ('',
    (r'^

请注意,此时您并没有将“myapp”放入 URL 中,而只是拥有一个基本 URL 方案,可以在部署时指向您想要的任何位置。

然后,为每个目标部署创建一个单独的 URLconf 模块(例如,测试与生产)并使用 django.conf.urls.defaults.include 函数 将 URL 连接到您想要的任意深度的基本 URL:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^PREFIX/myapp/', include('myapp.urls')),
    (r'^PREFIX/myapp2/', include('myapp2.urls')),
    (r'^PREFIX/myapp3/', include('myapp3.urls')),    
)

指向您的部署设置.py 使用此 URLconf 模块,而不是直接指向 myapp 的 URL 模块。

因为我的测试环境看起来与生产环境有很大不同,所以我喜欢为每个目标部署都有一个单独的设置模块。

, 'myapp.views.index'), (r'^view/

请注意,此时您并没有将“myapp”放入 URL 中,而只是拥有一个基本 URL 方案,可以在部署时指向您想要的任何位置。

然后,为每个目标部署创建一个单独的 URLconf 模块(例如,测试与生产)并使用 django.conf.urls.defaults.include 函数 将 URL 连接到您想要的任意深度的基本 URL:


指向您的部署设置.py 使用此 URLconf 模块,而不是直接指向 myapp 的 URL 模块。

因为我的测试环境看起来与生产环境有很大不同,所以我喜欢为每个目标部署都有一个单独的设置模块。

, 'myapp.views.view'), ... )

请注意,此时您并没有将“myapp”放入 URL 中,而只是拥有一个基本 URL 方案,可以在部署时指向您想要的任何位置。

然后,为每个目标部署创建一个单独的 URLconf 模块(例如,测试与生产)并使用 django.conf.urls.defaults.include 函数 将 URL 连接到您想要的任意深度的基本 URL:

指向您的部署设置.py 使用此 URLconf 模块,而不是直接指向 myapp 的 URL 模块。

因为我的测试环境看起来与生产环境有很大不同,所以我喜欢为每个目标部署都有一个单独的设置模块。

Design the URLs for myapp to be standalone (such that its URLs can be 'included' in the URLs of another project).

urlpatterns = patterns ('',
    (r'^

Notice that you're not putting 'myapp' in your URLs at this point, but simply have a basic URL scheme that can be pointed wherever you want at deployment time.

Then, create a separate URLconf module for each target deployment (e.g., test vs. production) and use the django.conf.urls.defaults.include function to wire up the URLs to whatever arbitrarily deep base URL you want:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^PREFIX/myapp/', include('myapp.urls')),
    (r'^PREFIX/myapp2/', include('myapp2.urls')),
    (r'^PREFIX/myapp3/', include('myapp3.urls')),    
)

Point your deployment settings.py to use this URLconf module instead of pointing directly at the URL module for myapp.

Because my test environment looks quite different from my production environment, I like to have a separate settings module for each target deployment.

, 'myapp.views.index'), (r'^view/

Notice that you're not putting 'myapp' in your URLs at this point, but simply have a basic URL scheme that can be pointed wherever you want at deployment time.

Then, create a separate URLconf module for each target deployment (e.g., test vs. production) and use the django.conf.urls.defaults.include function to wire up the URLs to whatever arbitrarily deep base URL you want:


Point your deployment settings.py to use this URLconf module instead of pointing directly at the URL module for myapp.

Because my test environment looks quite different from my production environment, I like to have a separate settings module for each target deployment.

, 'myapp.views.view'), ... )

Notice that you're not putting 'myapp' in your URLs at this point, but simply have a basic URL scheme that can be pointed wherever you want at deployment time.

Then, create a separate URLconf module for each target deployment (e.g., test vs. production) and use the django.conf.urls.defaults.include function to wire up the URLs to whatever arbitrarily deep base URL you want:

Point your deployment settings.py to use this URLconf module instead of pointing directly at the URL module for myapp.

Because my test environment looks quite different from my production environment, I like to have a separate settings module for each target deployment.

你如我软肋 2024-08-24 07:52:02

如果您的前缀在域名中,为什么不使用根相对网址?

我总是使用这种非常方便的网址

<a href="/myapp/view">blex</a>
<img src="/static/img/blex.png"/>

希望这会有所帮助。

if your prefix is in the domain name, why dont you use root-relative urls ?

i always use this kind of urls which is very handy

<a href="/myapp/view">blex</a>
<img src="/static/img/blex.png"/>

hope this helps.

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