Giter Site home page Giter Site logo

Reverse for 'categories' with arguments '( path, instance)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['category/(?P<path>.*)'] about django-mptt-urls HOT 16 CLOSED

c0ntribut0r avatar c0ntribut0r commented on June 26, 2024
Reverse for 'categories' with arguments '( path, instance)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['category/(?P.*)']

from django-mptt-urls.

Comments (16)

0xE111 avatar 0xE111 commented on June 26, 2024

The error message is quite verbose: your url rule 'category/(?P<path>.*)' receives only 1 keyword argument (path), so the tag should look like this

{% url 'categories' path=path %}

By the way, you are doing something strange. Please read django-mptt-urls documentation again, especially

class Category(MPTTModel):
    ...
    def get_absolute_url(self):
        return reverse('gallery', kwargs={'path': self.get_path()})

The better approach for your code is this

<a href="{{ instance.get_absolute_url }}?query=...">

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

thanks alex....i tried it ...but throws this error..'NoneType' object has no attribute 'get_descendants'

somehow the instance becomes none....

here is the view

def category(request, path, instance, extra):
if instance:
instance.save()

queryset = Product.objects.filter(category__in=instance.get_descendants(include_self=True))

color = request.GET.get('query')

if query:
    queryset = queryset.filter(optiongroup__color=query)

return render(
    request,
    'products/prodgrid.html',
    {
        'instance': instance,
        'children': instance.get_children() if instance else Category.objects.root_nodes(),
        'extra': extra,
        'queryset': queryset
    }
)

from django-mptt-urls.

0xE111 avatar 0xE111 commented on June 26, 2024

Maybe this will help

    queryset = Product.objects.filter(category__in=instance.get_descendants(include_self=True)) if instance else Product.objects.all()

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

It won't as it shows all products if instance is none...why the instance is becoming none when sending the query?

from django-mptt-urls.

0xE111 avatar 0xE111 commented on June 26, 2024

If resolution fails, instance will be None.

So, probably the ?P<path>.* part is empty (you open a 'root' page) or something is going wrong. If you're using v2.0.2 check whether your url ends up with slash (ie /products/slug1/slug2**/**)

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

No its not ending with that.....though I have given as u said in the link ...when I click on it ...reloads the page with no instance

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

The resolution fails when I append that query string....wonder why?

from django-mptt-urls.

0xE111 avatar 0xE111 commented on June 26, 2024

Insert this in your views.py and tell me the output:

def category(request, path, instance, extra):
    print('Path: [{}]'.format(path))
    slug = path.split('/')[-2]
    print('Slug: [{}]'.format(slug))
    if slug:
        for candidate in Product.objects.filter(slug=slug):
            print('Candidate slug: [{}]'.format(candidate.slug))
   # ... your code following ...

from django-mptt-urls.

0xE111 avatar 0xE111 commented on June 26, 2024

Ah, I think I got it... Still write the output

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

list index out of range

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    File "C:\Users\lenovo\Desktop\plump\Plumpin\src\mptt_urls__init__.py" in call
  2.     return self.view(_args, *_kwargs)
    
    File "C:\Users\lenovo\Desktop\plump\Plumpin\src\products\views.py" in category
  3. slug = path.split('/')[-2]
    

Exception Type: IndexError at /category/women
Exception Value: list index out of range

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

the resolution fails when
category/women/?color=blue

from django-mptt-urls.

0xE111 avatar 0xE111 commented on June 26, 2024

I've made some changes, try to update
116590e

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

OK Alex....just keep this issue open for sometime...if incase

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

updated...what changes did u make?

from django-mptt-urls.

Adrafe-Rinzzler avatar Adrafe-Rinzzler commented on June 26, 2024

what happens when i m sending request to category function from another template ...say header.html
which has search box to query on category objects....then that path resolution fails as there is no instance for it.....i tried with request.get_full_path to get the path of that particular page....but not getting passed.


form method = "GET" action = "{% url 'categories' path=request.get_full_path %} ">
input type= "text" name='q' style="height:45px; width:400px; padding:8px" value = '{{ request.Get.q }}'placeholder="Search"/>
button type="submit" class="btn btn-default" aria-label="Left Align" style="border-radius: 0px; background-color:#333333; width:50px; border-color:#333333; padding: 15px 12px; margin-top:1px;">

/button>
/form>

from django-mptt-urls.

0xE111 avatar 0xE111 commented on June 26, 2024

Time cures :)

from django-mptt-urls.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.