我正在做的事情:
url(r'^confirmemail/[a-bA-z0-9]+/', 'blog.views.confirmemail'),
Run Code Online (Sandbox Code Playgroud)
确切的网址是这样的:http://127.0.0.1:8000/confirmemail/tubwp2n0a6或http://127.0.0.1:8000/confirmemail/tubwp2n0a6/
字符串参数的长度为十(10).
如何在urls.py中写入该url?
工作:
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的内置管理站点).我希望一个域名指向公共站点,另一个域名指向管理站点.(即所以/index.html途径,例如,将指向在取决于域名其他应用的图.)每个应用程序有其自己的URL配置和它们都被包括到主URL配置.最好的方法是什么?
当我使用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) 如何获取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)
我正在写一个需要这个的脚本.谢谢!
我有两个网址:
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的那一部分获取reviews或tips参与视图以在同一视图中应用不同的逻辑,我该怎么做?
我是Django的新手.我要写一个moke.我的服务器将查看特定地址.像这样:
portal/client_api.ashx?client=SAPRA&key=1234234&func=status&code=99999
我写:
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)
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中跳过它.那我该怎么办?
我有一种情况,希望你能帮助我.我已经阅读了一些关于获取SO current_url和 url 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比较新,所以请愚蠢地解决这个问题.
我非常感谢你的帮助.非常感谢!
我import views在Django项目中遇到了一个奇怪的问题.我不知道它是否是造成问题PyCharm的Django.所以PyCharm说它不能import views.py存档,但它在我运行服务器时起作用.
这是图片:
你知道问题出在哪里吗?
编辑:
根据Inlangers的回答,我试图改变导入vlado_web.translations import views,但没有帮助,而且,它提出
Exception Value:
No module named translations
当我在from translations import views那里,它正常工作,但PyCharm说它无法解决.
django ×10
django-urls ×10
django-views ×4
python ×4
django-1.3 ×1
httprequest ×1
import ×1
pycharm ×1
regex ×1
url ×1
url-mapping ×1