Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are templates to django-filter package?

I am a little bit confused.

https://github.com/carltongibson/django-filter/blob/develop/django_filters/rest_framework/backends.py

From line 31 to 37 - here is a logic, if I have crispy instaled, package should use django_filters/rest_framework/crispy_form.html file.

I have installed all newest packages of django-filter and crispy forms, but all the time I have an error in my code:

Exception Type: TemplateDoesNotExist Exception Value:

django_filters/rest_framework/crispy_form.html

Could you please explain me where I can find all needed templates? Which repo? I don't see these files in django-filter repo, so I am little bit lost.

like image 733
pmoniq Avatar asked Nov 06 '16 16:11

pmoniq


People also ask

Where are Django templates?

To configure the Django template system, go to the settings.py file and update the DIRS to the path of the templates folder. Generally, the templates folder is created and kept in the sample directory where manage.py lives. This templates folder contains all the templates you will create in different Django Apps.

Can I filter in a Django template?

You can't do this, which is by design. The Django framework authors intended a strict separation of presentation code from data logic. Filtering models is data logic, and outputting HTML is presentation logic.

What are template tags in Django?

Django Code The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client.


2 Answers

You may need to add 'django_filters' to INSTALLED_APPS. I had same issue resolved by doing this.

like image 81
Farhan Malhi Avatar answered Oct 26 '22 14:10

Farhan Malhi


I have installed all newest packages of django-filter and crispy forms...

Please check this.

The backend catches the missing template exception so you shouldn't see that error.

The reason you can't see the template file is that the default templates are defined in the module, to avoid the extra files and the need to add Django Filter to INSTALLED_APPS. You can override these by adding files at the expected path(s).

The behaviour you're seeing is unexpected so if you can reduce it to a minimal reproducible example please open an issue on GitHub.

Please look at the test case here — this covers the exact behaviour:

Ensure backend renders default if template path does not exist

The question is, why is that not working in your case?

like image 2
Carlton Gibson Avatar answered Oct 26 '22 14:10

Carlton Gibson