标签: django-urls

如何设置一个带有一个带有aphanumeric字符串的参数的URL?

我正在做的事情:

url(r'^confirmemail/[a-bA-z0-9]+/', 'blog.views.confirmemail'),
Run Code Online (Sandbox Code Playgroud)

确切的网址是这样的:http://127.0.0.1:8000/confirmemail/tubwp2n0a6http://127.0.0.1:8000/confirmemail/tubwp2n0a6/

字符串参数的长度为十(10).

如何在urls.py中写入该url?

python django url django-urls

1
推荐指数
1
解决办法
68
查看次数

使用前缀时Django Url Dispatcher问题

工作:

urlpatterns = patterns('',
    (r'^$', views.index),
    (r'^test/$|test/(\d+)/$', views.test_page),
    (r'^(name)/$', views.index),
    (r'^(username)/$', views.index),
)
Run Code Online (Sandbox Code Playgroud)

不工作:

urlpatterns = patterns('views',
    (r'^$', index),
    (r'^test/$|test/(\d+)/$', test_page),
    (r'^(name)/$', index),
    (r'^(username)/$', index),
)
Run Code Online (Sandbox Code Playgroud)

错误:

Django Version:     1.3
Exception Type:     NameError
Exception Value:    name 'index' is not defined
Exception Location: /home/nolhian/Documents/Test/../test/urls.py in <module>, line 8
Run Code Online (Sandbox Code Playgroud)

我跟着文档做了这个,我哪里出错了?

django django-urls django-views

1
推荐指数
1
解决办法
339
查看次数

Django - 每域URLConf?

我的Django项目中有两个应用程序:面向公众的应用程序和管理应用程序(不是 django的内置管理站点).我希望一个域名指向公共站点,另一个域名指向管理站点.(即所以/index.html途径,例如,将指向在取决于域名其他应用的图.)每个应用程序有其自己的URL配置和它们都被包括到主URL配置.最好的方法是什么?

python django django-urls

1
推荐指数
1
解决办法
1960
查看次数

如何在django中启用/ static/css URL enable

当我使用MEDIA_URL或STATIC_URL指向/ static /当前将MEDIA_URL设置为/ static /并在CSS文件的路径中使用它时,如:

<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}css/css.css" />
Run Code Online (Sandbox Code Playgroud)

它指向/static/css.css,但尝试http://localhost/static/css.css给出404错误.

我有设置:

.....
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/static/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT …
Run Code Online (Sandbox Code Playgroud)

django django-urls django-settings django-1.3 django-static

1
推荐指数
1
解决办法
2105
查看次数

我不知道何时在django.core.urlresolvers模块中使用reverse()

我看完了文档reverse()Django的URL调度的方法.

什么时候有用?

谢谢!

django django-urls

1
推荐指数
1
解决办法
4360
查看次数

如何在Django中获取与url相对应的视图(使用url)?

如何获取url映射到的视图?例如:

urlpatterns = patterns('',
                       url(r'^login/$', 'registration.views.Login'),)
Run Code Online (Sandbox Code Playgroud)

我该如何使用字符串'login/'返回registration.views.Login

如果我不清楚,我想编写一个执行以下操作的函数(我将其称之为foo):

>>> foo('login/')
<function Login at 0x010101010>
>>>
Run Code Online (Sandbox Code Playgroud)

我正在写一个需要这个的脚本.谢谢!

python django django-urls url-mapping django-views

1
推荐指数
1
解决办法
54
查看次数

如何在Django视图中获取url的一部分?

我有两个网址:

url(r'^(?P<slug>[^\.]+)/reviews/$', Someview.as_view(), name="someview"),
url(r'^(?P<slug>[^\.]+)/tips/$', Someview.as_view(), name="someview")
Run Code Online (Sandbox Code Playgroud)

我需要根据url的那一部分获取reviewstips参与视图以在同一视图中应用不同的逻辑,我该怎么做?

django django-templates django-urls django-views

1
推荐指数
1
解决办法
1205
查看次数

我该如何处理查询"?" 在我的django urls.py中

我是Django的新手.我要写一个moke.我的服务器将查看特定地址.像这样:

portal/client_api.ashx?client=SAPRA&key=1234234&func=status&code=99999

我写:

urls.py

from django.conf.urls import patterns, url
from rt_moke import views
urlpatterns = patterns('',
    url(r'code=(?P<code_id>\w+)/', views.Sapata, name='sapata'),
    )
Run Code Online (Sandbox Code Playgroud)

和views.py

from django.http import HttpResponse
status = {u"99999": u'{"code": "99999","status": "undelivered"}',\
     u"88888": u'{"code": "88888","status": "delivered"}',\
     }
def Sapata(request, code_id):
    return HttpResponse(status[code_id])
Run Code Online (Sandbox Code Playgroud)

当我请求ortal/client_api.ashx?client=SAPRA&key=1234234&func=status&code=99999没有?标记的p时- 它可以工作,而且?- 不是.我明白,它是查询字符串,Django在regexp中跳过它.那我该怎么办?

python regex django django-urls httprequest

1
推荐指数
1
解决办法
507
查看次数

Django:从当前实际页面获取当前url路径

我有一种情况,希望你能帮助我.我已经阅读了一些关于获取SO current_urlurl TEMPLATE_CONTEXT_PROCESSORS(最相关)的当前url路径的帖子和答案.但它似乎不适合我想做的事情.我有一个观点:

def fish_search(request):
    args = {}
    #irrelevant code here
    args['fishes'] = fishes
    args['current_path'] = request.get_full_path()
    return render_to_response('ajax_search.html', args)
Run Code Online (Sandbox Code Playgroud)

在我的ajax_search.html中:

<a id="search-results" href="{{ current_path }}"></a>
Run Code Online (Sandbox Code Playgroud)

和base.html:

div id="search-results" ></div>
Run Code Online (Sandbox Code Playgroud)

Javascript会将搜索结果转储到base.html.并且base.html在fishMarket.html,fishDictionary.html,fishRumour.html等中进行了扩展.所以,遗憾的是,显示的路径都是"/ search /"

我希望路径是/ fishMarket /如果我从fishMarket.html搜索,/ fishDictionary /应该出现,如果我从fishDictionary.html搜索,同样,/ fishRumour /如果我从fishRumour.html搜索.有没有人遇到过这种情况?你是怎么解决这个问题的?我对django比较新,所以请愚蠢地解决这个问题.

我非常感谢你的帮助.非常感谢!

django django-templates django-urls django-views

1
推荐指数
1
解决办法
1万
查看次数

PyCharm/Django - 无法导入模块views.py(IDE错误)

import viewsDjango项目中遇到了一个奇怪的问题.我不知道它是否是造成问题PyCharmDjango.所以PyCharm说它不能import views.py存档,但它在我运行服务器时起作用.

这是图片:

在此输入图像描述

你知道问题出在哪里吗?

编辑: 根据Inlangers的回答,我试图改变导入vlado_web.translations import views,但没有帮助,而且,它提出

Exception Value:
No module named translations

当我在from translations import views那里,它正常工作,但PyCharm说它无法解决.

在此输入图像描述

django import intellij-idea django-urls pycharm

1
推荐指数
1
解决办法
398
查看次数