我正在尝试使用Django-recurrence模块。没有javascript_catalog在"设置国际化"根据指示:
# If you already have a js_info_dict dictionary, just add
# 'recurrence' to the existing 'packages' tuple.
js_info_dict = {
'packages': ('recurrence', ),
}
# jsi18n can be anything you like here
urlpatterns = patterns(
'',
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
)
我在国际化之前看到的一切,如下: - 重现的上半部分" javascript-image"没有显示。绿色文本部分(添加规则和添加日期)是唯一显示:
+Add rule+Add date
根据文档我期待的内容如下所示:
应用程序/ urls.py
js_info_dict = {
'packages': ('recurrence', ),
}
urlpatterns = patterns(#'',
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
url(r'^room/$', CreateConfRoom_Sch.as_view(), name='CreateConfRoom_Sch'),
应用程序/ forms.py
class ScheduleConfRoom(ModelForm):
class Meta:
model = Schedule
fields = ('name', 'room', 'message', 'recurrences',)
widgets = {
'message': Textarea(attrs={'cols': 25, 'rows': 6}),
}
应用程序/ views.py
class CreateConfRoom_Sch(CreateView):
form_class = ScheduleConfRoom
template_name = "schedule.html"
success_url = '/'
应用程序/ models.py
class Schedule(models.Model):
name = models.CharField(max_length=30, default='Example')
room = models.ForeignKey(Room) # default='Empty')
message = models.CharField(max_length=918)
recurrences = RecurrenceField()
schedule.html
<form method="POST" action="{% url 'upload_file' %}" >
{% csrf_token %}
{{ form.media }}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
请帮忙!!!我做错了什么?当我在urls.py中有javascript_catalog时,主题中的错误显示。但是当我没有它时,只有&#34; +添加规则+添加日期&#34;示出。
AttributeError at /schedule/room/
'str' object has no attribute 'resolve'
Request Method: GET
Request URL: http://192.168.1.199:8000/schedule/room/
Django Version: 1.8.13
Exception Type: AttributeError
Exception Value: 'str' object has no attribute 'resolve'
Exception Location: /usr/local/lib/python3.4/site-packages/django/core/urlresolvers.py in resolve, line 367
Python Executable: /usr/local/bin/python3.4
Python Version: 3.4.4
回溯切换到复制并粘贴视图
/usr/local/lib/python3.4/site-packages/django/core/handlers/base.py in get_response
resolver_match = resolver.resolve(request.path_info)
...
▶ Local vars
/usr/local/lib/python3.4/site-packages/django/core/urlresolvers.py in resolve
sub_match = pattern.resolve(new_path)
...
▶ Local vars
/usr/local/lib/python3.4/site-packages/django/core/urlresolvers.py in resolve
sub_match = pattern.resolve(new_path)
...
▶ Local vars
First Trace
urlconf 'mal.urls'
middleware_method <bound method SecurityMiddleware.process_request of <django.middleware.security.SecurityMiddleware object at 0x8091b7a20>>
response None
resolver <RegexURLResolver 'mal.urls' (None:None) ^/>
self <django.core.handlers.wsgi.WSGIHandler object at 0x80836cc88>
第二次追踪
pattern <RegexURLResolver <module 'app.urls' from '/usr/home/msg/code/mal/app/urls.py'> (None:None) ^schedule/>
sub_tried None
new_path 'schedule/room/'
match <_sre.SRE_Match object; span=(0, 1), match='/'>
path '/schedule/room/'
tried [[<RegexURLResolver <RegexURLPattern list> (admin:admin) ^admin/>],
[<RegexURLResolver <module 'allauth.urls' from '/usr/home/msg/code/mal/allauth/urls.py'> (None:None) ^accounts/>],
[<RegexURLResolver <module 'app.urls' from '/usr/home/msg/code/mal/app/urls.py'> (None:None) ^upload/>]]
self <RegexURLResolver 'mal.urls' (None:None) ^/>
第三条跟踪
pattern 'app.views'
new_path 'room/'
match <_sre.SRE_Match object; span=(0, 9), match='schedule/'>
path 'schedule/room/'
sub_match None
tried [[<RegexURLPattern None ^jsi18n/$>]]
self <RegexURLResolver <module 'app.urls' from '/usr/home/msg/code/mal/app/urls.py'> (None:None) ^schedule/>
答案 0 :(得分:0)
回溯的locals
信息显示它尝试使用以下字符串作为匹配模式:
pattern 'app.views'
该字符串取自urlpatterns
文件中的app/urls.py
序列,您只发布了 part 。
此外,您忘记了第一条规则的url
功能:
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
# ^ no url
这使得它只是一个元组,然后第一个元素应该是一个正则表达式。添加url
电话:
urlpatterns = patterns(#'',
url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
url(r'^room/$', CreateConfRoom_Sch.as_view(), name='CreateConfRoom_Sch'),
但是,您需要修复所有规则。