AttributeError: 'str' object has no attribute 'regex' django 1.9

前端 未结 4 1309
无人共我
无人共我 2021-02-19 22:28

I am working with django 1.9 and I am currently coding - in Windows Command Prompt - python manage.py makemigrations and the error:

AttributeErr

4条回答
  •  猫巷女王i
    2021-02-19 22:38

    For Django 2

    from django.urls.resolvers import get_resolver, URLPattern, URLResolver
    
    urls = get_resolver()
    
    def if_none(value):
        if value:
            return value
        return ''
    
    def print_urls(urls, parent_pattern=None):
        for url in urls.url_patterns:
            if isinstance(url, URLResolver):
                print_urls(url, if_none(parent_pattern) + if_none(str(url.pattern)))
            elif isinstance(url, URLPattern):
                print(f"{url} ({url.lookup_str})")
                print('----')
    print_urls(urls)
    

提交回复
热议问题