简体   繁体   English

AttributeError:'str'对象没有属性'resolve'

[英]AttributeError: 'str' object has no attribute 'resolve'

I am trying to use Django-recurrence module. 我正在尝试使用Django递归模块。 Without the javascript_catalog under "setting up internationalization" according to instruction : 如果没有按照说明在“设置国际化”下的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),
)

All I see even before internationalization, is below: - The upper part of the reccurrence "javascript-image" is not showing. 我什至在国际化之前只看到以下内容:-递归“ javascript-image”的上部未显示。 The green text part(Add Rule and Add date) is the only thing showing: 绿色文本部分(添加规则和添加日期)是唯一显示的内容:

+Add rule+Add date

What I am expecting according to documentation is shown below: 根据文档,我期望的结果如下所示:

在此处输入图片说明

app/urls.py app / 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'),

app/forms.py app / forms.py

class ScheduleConfRoom(ModelForm):
    class Meta:
        model = Schedule
        fields = ('name', 'room', 'message', 'recurrences',)
        widgets = {
            'message': Textarea(attrs={'cols': 25, 'rows': 6}),
        }

app/views.py app / views.py

class CreateConfRoom_Sch(CreateView):
    form_class = ScheduleConfRoom
    template_name = "schedule.html"
    success_url = '/'

app/models.py app / 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 schedule.html

<form method="POST" action="{% url 'upload_file' %}" >
    {% csrf_token %}
    {{ form.media }}
    {{ form.as_p }}
<button type="submit">Submit</button>
</form>

Please help!!! 请帮忙!!! What did I do wrong? 我做错了什么? The error in the subject shows when I have the javascript_catalog in the urls.py. 当我在urls.py中包含javascript_catalog时,将显示主题中的错误。 But When I don't have it, only "+Add Rule +Add date" shows. 但是当我没有它时,仅显示“ +添加规则+添加日期”。

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

Traceback Switch to copy-and-paste view 追溯切换到复制和粘贴视图

/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>

Second trace 第二条痕迹

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) ^/>

Third Trace 第三痕迹

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/>

The locals information of your traceback shows it tried to use the following string as a match pattern: 您的回溯的locals信息显示它试图使用以下字符串作为匹配模式:

pattern  'app.views'

That string was taken from the urlpatterns sequence in your app/urls.py file, which you only posted part of. 该字符串取自您的app/urls.py文件中的urlpatterns序列,您只发布了其中的一部分

In addition, you forgot the url function on the first rule: 此外,您忘记了第一个规则的url函数:

(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
# ^ no url

That makes it just a tuple, and the first element is then expected to be a regular expression. 这使得它只是一个元组,然后第一个元素应该是正则表达式。 Add in the url call: 添加url调用:

urlpatterns = patterns(#'',
    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
    url(r'^room/$', CreateConfRoom_Sch.as_view(), name='CreateConfRoom_Sch'),

You'll need to fix all your rules however. 但是,您需要修复所有规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django 查看 AttributeError: 'str' object 没有属性 'get' - Django view AttributeError: 'str' object has no attribute 'get' AttributeError:&#39;NoneType&#39;对象没有属性&#39;is_active&#39; - AttributeError: 'NoneType' object has no attribute 'is_active' sanic( ) - AttributeError: 'Request' object 没有属性 'split' - sanic( ) - AttributeError: 'Request' object has no attribute 'split' AttributeError:&#39;WebElement&#39;对象没有属性&#39;getElementById&#39; - AttributeError: 'WebElement' object has no attribute 'getElementById' AttributeError问题:&#39;WebDriver&#39;对象没有属性&#39;manage&#39; - Issue with AttributeError: 'WebDriver' object has no attribute 'manage' 格式错误:AttributeError: 'JsonResponse' object has no attribute '_headers' - Error in formatting: AttributeError: 'JsonResponse' object has no attribute '_headers' Flask + Ajax 集成:AttributeError:&#39;WSGIRequestHandler&#39; 对象没有属性 &#39;environ&#39; - Flask + Ajax Integration : AttributeError: 'WSGIRequestHandler' object has no attribute 'environ' AttributeError:“ unicode”对象没有属性“ get”-在Django表单中 - AttributeError: 'unicode' object has no attribute 'get' - In Django Forms /Customer/Visit 'WSGIRequest' object 处的 AttributeError 在 django 中没有属性 'is_ajax' - AttributeError at /Customer/Visit 'WSGIRequest' object has no attribute 'is_ajax' in django / accounts / regist_save /&#39;User&#39;对象上的AttributeError没有属性&#39;user&#39; - AttributeError at /accounts/regist_save/ 'User' object has no attribute 'user'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM