Changes between Version 1 and Version 2 of Ticket #33357


Ignore:
Timestamp:
Dec 11, 2021, 8:48:26 AM (3 years ago)
Author:
Baptiste Mispelon
Comment:

It turns out my initial tests were incorrect and I cannot actually reproduce your issue.

Using class MyView(SuccessMessageMixin, LoginView) works fine for me, there must be something else that's broken in your setup.

I've marked the ticket as "needs info" and restored your original description. Could you reopen the ticket with some details on how to reproduce your issue? In particular, how do you display the messages in your templates.

Thanks.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33357

    • Property Component contrib.authcontrib.messages
    • Property Status assignedclosed
    • Property Resolutionneedsinfo
  • Ticket #33357 – Description

    v1 v2  
    1 I have a problem with `SuccessMessageMixin, LoginView`. There is no problem with `CreateView`:
     1I have a problem with SuccessMessageMixin, LoginView. There is no problem with CreateView:
    22{{{#!py
    33class CreateRoom(SuccessMessageMixin, CreateView):
     4
    45    template_name = 'base/room_form.html'
    56    form_class = RoomForm
     
    89}}}
    910
    10 I can capture and use 'Message' in template but with `LoginView`
     11I can capture and use 'Message' in template but with LoginView
    1112{{{#!py
    1213class Login(SuccessMessageMixin, LoginView):
     14
    1315    template_name = 'registration/login.html'
    1416    success_url = reverse_lazy('home')
     
    1618}}}
    1719
    18 I can not capture 'Message' with `LoginView`.
     20I can not capture 'Message' with LoginView.
     21
     22project urls:
     23{{{#!py
     24
     25urlpatterns = [
     26
     27    path('admin/', admin.site.urls),
     28    path(, include('django.contrib.auth.urls')),
     29    path(, include('base.urls')),
     30
     31]
     32}}}
     33
     34the base apps urls:
     35{{{#!py
     36# app_name = 'base'
     37
     38urlpatterns = [
     39
     40    path(, views.Home.as_view(), name='home'),
     41    path('room/<int:pk>/', views.Room.as_view(), name='room'),
     42    path('create-room/', views.CreateRoom.as_view(), name='create-room'),
     43    path('update-room/<int:pk>/', views.UpdateRoom.as_view(model=Room), name='update-room'),
     44    path('delete-room/<int:pk>/', views.DeleteRoom.as_view(model=Room), name='delete-room'),
     45    path('login/', views.Login.as_view(), name='login')
     46
     47]
     48}}}
     49
     50settings.py:
     51{{{#!py
     52
     53INSTALLED_APPS = [
     54
     55        # Default django apps
     56        'django.contrib.admin',
     57        'django.contrib.auth',
     58        'django.contrib.contenttypes',
     59        'django.contrib.sessions',
     60        'django.contrib.messages',
     61        'django.contrib.staticfiles',
     62
     63        # My custom apps
     64        'base.apps.BaseConfig',
     65
     66]
     67
     68MIDDLEWARE = [
     69
     70    'django.middleware.security.SecurityMiddleware',
     71    'django.contrib.sessions.middleware.SessionMiddleware',
     72    'django.middleware.common.CommonMiddleware',
     73    'django.middleware.csrf.CsrfViewMiddleware',
     74    'django.contrib.auth.middleware.AuthenticationMiddleware',
     75    'django.contrib.messages.middleware.MessageMiddleware',
     76    'django.middleware.clickjacking.XFrameOptionsMiddleware',
     77
     78]
     79
     80ROOT_URLCONF = 'studybud.urls'
     81
     82TEMPLATES = [
     83
     84    {
     85
     86        'BACKEND': 'django.template.backends.django.DjangoTemplates',
     87        'DIRS': [BASE_DIR / 'templates']
     88        ,
     89        'APP_DIRS': True,
     90        'OPTIONS': {
     91
     92            'context_processors': [
     93
     94                'django.template.context_processors.debug',
     95                'django.template.context_processors.request',
     96                'django.contrib.auth.context_processors.auth',
     97                'django.contrib.messages.context_processors.messages',
     98
     99            ],
     100
     101        },
     102
     103    },
     104
     105]
     106
     107WSGI_APPLICATION = 'studybud.wsgi.application'
     108
     109# Database
     110# ​https://docs.djangoproject.com/en/4.0/ref/settings/#databases
     111
     112DATABASES = {
     113
     114    'default': {
     115
     116        'ENGINE': 'django.db.backends.sqlite3',
     117        'NAME': BASE_DIR / 'db.sqlite3',
     118
     119    }
     120
     121}
     122
     123# Password validation
     124# ​https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
     125
     126AUTH_PASSWORD_VALIDATORS = [
     127
     128    {
     129
     130        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
     131
     132    },
     133    {
     134
     135        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
     136
     137    },
     138    {
     139
     140        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
     141
     142    },
     143    {
     144
     145        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
     146
     147    },
     148
     149]
     150
     151# Internationalization
     152# ​https://docs.djangoproject.com/en/4.0/topics/i18n/
     153
     154LANGUAGE_CODE = 'en-us'
     155
     156TIME_ZONE = 'UTC'
     157
     158USE_I18N = True
     159
     160USE_TZ = True
     161
     162# Static files (CSS, JavaScript, Images)
     163# ​https://docs.djangoproject.com/en/4.0/howto/static-files/
     164
     165STATIC_URL = 'static/'
     166
     167# Default primary key field type
     168# ​https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
     169
     170DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
     171
     172# Login redirect
     173LOGIN_REDIRECT_URL = 'home'
     174LOGIN_URL = 'login'
     175}}}
Back to Top