使用 django 模板 url 标签时,项目名称自动插入到 url 中
我将“url”模板标签应用到当前 Django 项目中的所有链接。
我的网址命名如下...
url(r'^login/$', 'login', name='site_login'),
这允许我访问我网站根目录的 /login 。我的模板标签定义如下...
<a href="{% url site_login %}">
它工作正常,除了 Django 自动将该网址解析为 /myprojectname/login,而不是 /login。两个网址都可以访问。为什么?是否有删除项目名称的选项?所有 url 标签都会出现这种情况,而不仅仅是这个。
I am applying the 'url' template tag to all links in my current Django project.
I have my urls named like so...
url(r'^login/
This allows me to access /login at my site's root. I have my template tag defined like so...
<a href="{% url site_login %}">
It works fine, except that Django automatically resolves that url as /myprojectname/login, not /login. Both urls are accessible. Why? Is there an option to remove the projectname? This occurs for all url tags, not just this one.
, 'login', name='site_login'),
This allows me to access /login at my site's root. I have my template tag defined like so...
It works fine, except that Django automatically resolves that url as /myprojectname/login, not /login. Both urls are accessible. Why? Is there an option to remove the projectname? This occurs for all url tags, not just this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,这是我的 apache2 配置的问题。我基本上从 django 网站复制了指令,做了一个小修改:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration
我进行了更改,以便我的 Django 项目将在我网站的根目录中提供服务。
我必须从 django.root 选项中删除“/mysite”。我的最终输出如下所示,在 django.root 之后没有任何值:
根据记录,我正在运行:
Django 1.0
阿帕奇2.2
mod_python 3.3.1(我认为...:))
Ubuntu Hardy 8.04.4
从此处复制: http://groups.google.com /group/django-users/msg/5e79ed1e694a3776
Apparently, it was a problem with my apache2 configuration. I basically copied the directives from the django website, with one small modification:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration
I changed to so my Django project would be served at my site's root directory.
I had to remove '/mysite' from the django.root option. My final output looks like this, with no value after django.root:
For the record, I am running:
Django 1.0
Apache 2.2
mod_python 3.3.1 (i think... :))
Ubuntu Hardy 8.04.4
Copied from here: http://groups.google.com/group/django-users/msg/5e79ed1e694a3776
在你的 url conf 中,django 比另一个更早地遇到这个 url 模式。
由于 url 解析是一一完成的,只需在主 urls.py 中包含之前在主登录中移动即可
In your url conf django encounters this url pattern earlier than the other one.
Since url resolution is done one by one, just move around the main login before the include within the main urls.py