Redirect is "loosing" querystring

Dear all,

on my Django website I am calling a view (“rate”) and after executing I redirect to another view (“spiritcatalog”) to render and return a page, this works fine so far.

Now I added django-filter to my application and want to keep the filter setting when a user rates an item but I am not able to somehow forward the querystring to it is kept by the catalog function

Everything works fine when I call the URL in my browser like this:

type or paste code here

http://127.0.0.1:8000/mybar/spiritcatalog?spirit_type__spirit_type_name=165&brand=&spirit_name=`

But even when I explicitly add the complete relative url to redirect like below it seems to cut off the query string and just returns the catalog page without the filter

return redirect("/mybar/spiritcatalog?spirit_type__spirit_type_name=165&brand=&spirit_name=")

Does anyone has or had a similar issue and any hint what I am missing?
Thank you in advance!

Here an extract of my urls.py

urlpatterns = [
    path('', views.mybar, name='mybar'),

    path('<int:spirit_id>/rate/<int:rating>', views.rate, name='rate'),
    path('spiritcatalog', views.show_spirit_catalog, name='spiritcatalog'),

]

This doesn’t match what I’m seeing in my test environment.

This leads me to think that there’s something else involved here.

If you want to pursue this further, we’d need to see more details about your environment and your project.

Please start by identifying what versions of Django and Python are being used and what your settings are for INSTALLED_APPS and MIDDLEWARE.

First of all thank you for the quick response!

I am using the following python version:

Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32

and have the following packages installed:

Package           Version
----------------- -------
asgiref           3.7.2
autopep8          2.0.4
Django            5.0
django-countries  7.5.1
django-filter     23.5
pip               23.3.2
pycodestyle       2.11.1
python-dotenv     1.0.0
setuptools        69.0.2
sqlparse          0.4.4
tomli             2.0.1
typing_extensions 4.9.0
tzdata            2023.3

Here the requested settings extract:

INSTALLED_APPS = [
    'homepage',
    'mybar',
    'linkcollection',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_filters',
    'django_countries',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

When checking the terminal out I see the following and I added a debug message that shows that the queryset gets lost

DEBUG mybar.views->rate: Rated 5 for Aberlour - A'bunadh (Batch 49) [Spirit ID=175]
[25/Feb/2024 10:42:38] "GET /mybar/175/rate/5 HTTP/1.1" 302 0
DEBUG mybar.views->show_spirit_catalog: REQUEST.GET: <WSGIRequest: GET '/mybar/spiritcatalog?spirit_type__spirit_type_name=165&brand=&spirit_name='>
DEBUG mybar.views->show_spirit_catalog: Found 9 bottles for user=admin when loading the drinks menu
[25/Feb/2024 10:42:38] "GET /mybar/spiritcatalog?spirit_type__spirit_type_name=165&brand=&spirit_name= HTTP/1.1" 200 41340
DEBUG mybar.views->show_spirit_catalog: REQUEST.GET: <WSGIRequest: GET '/mybar/spiritcatalog'>
DEBUG mybar.views->show_spirit_catalog: Found 9 bottles for user=admin when loading the drinks menu
[25/Feb/2024 10:42:38] "GET /mybar/spiritcatalog HTTP/1.1" 200 202099

According to your question I will meanwhile try if changing the order of the entries in the settings makes a difference.

In general my objective is to keep the filter settings and ideally the position on the page after a function is executed.

Thank you!

I think I found my mistake and I am sorry for bothering you, the used JavaScript function in my template s just calling the view again without the query set after processing the rating function. (sometimes sleeping a bit helps to see clearer again). So I close this thread and will check further before coming back again.