问题标签 [urlconf]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
django - Django urls.py does not recognise URL
I have a library application with the following file structure
#xA;In loan_subviews.py
, there is a view method as so:
However, in urls.py
when I do something like the following,
it throws a NameError: name 'generate_loan_view' is not defined
error. How can I fix so that the URLConf file can see my view method?
python - Django URL 模式未出现在生产中,找不到页面
问题
我为代理页面创建了一个 url 模式,它在本地运行良好,但在项目投入生产时就不行了。尝试调试错误时,url 模式没有出现在 404 页面上url(r'^agencies/$', views.agencies, name='agencies')
_home.html
网页未找到
网址.py
视图.py
python - 为什么 URLconf 在本地工作但在生产中失败
我只是设置一个空的 django 项目来测试一个新服务器。我有我的 django 项目在本地工作,显示“Hello World!” 用于基本 URL 以及数据/应用程序域。
main_project/urls.py
main_project/mainsite/urls.py
main_project/data/urls.py
它是一个非常基本的设置,并且在本地使用python manage.py runserver
一切正常。
一个生产基本 url ( http://www.mondonect.com/ ) 有效,但数据 url ( http://www.mondonect.com/data ) 失败并出现以下错误:
奇怪的是它在本地工作但在生产中不起作用。
它的 apache 2 服务器带有 wsgi,ubuntu 14.04。Django 版本 1.10.2。
django - Django not displaying correct URL after reverse
There's lots of documentation about Django and the reverse()
method. I can't seem to locate my exact problem. Suppose I have two urlconfs like this:
and the two corresponding views like this:
Here, list.html
just extends my base template index.html
, which contains a drop down box with grade levels. When the user goes to /ParentLists, the main_page
view renders index.html with the drop down box as it should.
When the user picks a grade level from the drop down box (say 5th Grade), the template does a form submit, and main_page
once again executes - but this time the POST branch runs and the HttpResponseRedirect
takes the user to /ParentLists/05. This simply results in an HTML table pertaining to grade 5 being displayed below the drop down box.
The problem is, when the user now selects say 10th Grade, the table updates to show the grade 10 content, but the URL displayed is still /ParentLists/05. I want it to be /ParentLists/10.
Clearly, after the first selection, the main_page
view never executes again. Only foo
does...and so the HttpResponseRedirect
never gets called. How should I reorganize this to get what I'm looking for? Thanks in advance!
django - Django 网站加载空的根 urls.py 文件
我知道这感觉很初级,但我无法仅基于 doc 提出一个干净的解决方案。我有以下项目结构(为了保持问题简洁,我省略了 models.py、forms.py 等文件)
- 你好世界
- hello_world
- 网址.py
- app_2
- 网址.py
- app_3
- 网址.py
- 管理.py
- 网址.py
- 设置.py
- hello_world
如您所见,我的目标是urls.py
为每个应用程序创建一个单独的文件,然后将它们组装到根目录urls.py
中(与上面的列表处于同一级别settings.py
)。问题是我的根 urls.py 现在是 EMPTY (!!!),并且该站点仍在加载主页 !!! 我究竟做错了什么 ???请参阅以下详细信息:
设置.py:
ROOT_URLCONF = 'urls'
hello_world urls.py:
根 urls.py - 空!
管理.py:
regex - Django urlconf 无法解析有效的正则表达式
我在将 url 路由到 Django 中的视图时遇到问题。具体来说,我使用带有以下模式的 URL:
一个示例网址是My data/current/managetables
. 我检查了正则表达式是否返回 www.pyregex.com 上的预期捕获组(示例)
但是,实际访问 url 并不会导致调用视图。最重要的是,它适用于高度相似的 url:
如果我访问My data/current/managetab
该视图,则会按预期调用。此外,在 urlconf 中附加一个“/”也可以 - 但我不清楚为什么,即:
并且访问My data/current/managetables
会导致重定向到My data/current/managetables/
调用视图。
我很感激任何提示如何解决这个问题。
django - Django,外部链接url修改为项目url
我有一个 Django 项目,并希望将用户带到 openstreetmaps 中的外部链接,该链接由我的 Django 模型提供 lat 和 long 。在我看来,我开发了一个这样的网址:“ http://www.openstreetmap.org/?minlon=-92.024&minlat=57.5129102&maxlon=-91.52&maxlat=43.00&mlat=42.899&mlon=-91.774 ”并将其提供为我的模板中的一个变量。我的模板中的链接是:
<a id="map" target="_blank" href={{mapurl}}>map</a>
. {{mapurl}} 是我认为的 url。
问题是 Django 试图找到一个如下所示的 url conf:http: //127.0.0.1 :8000/beach/1825108/%22http://www.openstreetmap.org/?minlon=-92.0240039&minlat=42.78940921&maxlon= -91.5240039&maxlat=43.00940921&mlat=42.89940921&mlon=-91.7740039%22
而不是将用户带到新页面中的openstreetmap。
有什么想法吗?
python - Django 不呈现请求的视图
人们。我是一个初学者 Django 开发人员,如果这是一个基本问题,我很抱歉。
我有一个显示电影列表的网页,每部电影都有一个详细信息视图,但由于某种原因,永远不会呈现详细信息视图。
还有我的 urls.py
例如,当我尝试访问 /ytsmirror/4200/ 时,我没有收到任何错误,并且 Django 显然达到了正确的 URL 模式但没有呈现详细信息视图,它停留在索引视图上,没有任何更改。
我究竟做错了什么?谢谢。
python - django urlconf 直接从根目录到包含的应用程序逻辑
我一直在尝试解决这个问题一段时间,但一直未能找到有效的解决方案。也许有人可以帮助指出更好的方法!
我正在使用我的根 urlconf 将两个请求重定向到包含的应用程序:
这是kdi
应用程序的 urlconf:
^about/news/
使用从 root到应用程序 urlconf^about/recognition
的更精细的重定向似乎更聪明。^$
这仅适用于一种模式,但我想将其扩展为适用于两种模式。
是否会像^about/
从根目录定向到我可以检查的应用程序^/news$
或^/recognition$
在kdi
应用程序中更智能?^
如果没有匹配,那是否也可以使用根的包罗万象?是否可以request.path
从 urlconf 检查然后使用 if 语句指向正确的视图?或者也许name
在根目录中使用一个字段,然后在应用程序的 url 模式中通过该名称访问?
只是在解决这个逻辑时遇到了一些麻烦!
编辑:
从根 urlconf 中删除namespace
字段以限制混淆