Comments (16)
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.
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.
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.
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.
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.
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.
The resolution fails when I append that query string....wonder why?
from django-mptt-urls.
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.
Ah, I think I got it... Still write the output
from django-mptt-urls.
list index out of range
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
-
File "C:\Users\lenovo\Desktop\plump\Plumpin\src\mptt_urls__init__.py" in call
response = wrapped_callback(request, _callback_args, *_callback_kwargs)
-
File "C:\Users\lenovo\Desktop\plump\Plumpin\src\products\views.py" in category
return self.view(_args, *_kwargs)
-
slug = path.split('/')[-2]
Exception Type: IndexError at /category/women
Exception Value: list index out of range
from django-mptt-urls.
the resolution fails when
category/women/?color=blue
from django-mptt-urls.
I've made some changes, try to update
116590e
from django-mptt-urls.
OK Alex....just keep this issue open for sometime...if incase
from django-mptt-urls.
updated...what changes did u make?
from django-mptt-urls.
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.
Time cures :)
from django-mptt-urls.
Related Issues (12)
- Request to update Documentation for view routing HOT 1
- Optional trailing space HOT 1
- `mptt_urls` must be in settings.INSTALLED_APPS HOT 1
- 'NoneType' object has no attribute 'get_ancestors'
- AttributeError: 'NoneType' object has no attribute 'get'
- Add support for url namespaces when attaching url_mptt to namespaced pattern HOT 6
- url_mptt import error HOT 2
- Specify parent field HOT 1
- Not showing data for main categories HOT 5
- how can i access the urls as links? HOT 7
- how to filter on existing url HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-mptt-urls.