question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'WSGIRequest' object has no attribute 'session'

See original GitHub issue

Running python manage.py distill-local site-export produces the response CommandError: Failed to render view "/": 'WSGIRequest' object has no attribute 'session' URLs.py config:

from django.urls import path
from django.contrib.auth.views import LoginView, LogoutView

from . import views

from django_distill import distill_path

def get_index():
    return None
def get_ageVerification():
    return None
def get_register():
    return None
def get_login():
    return None
def get_profile():
    return None
def get_message():
    return None
def get_messages():
    return None
def get_faq():
    return None
def get_legal():
    return None


urlpatterns = [
    distill_path('', views.index, name='index', distill_func=get_index, distill_file="index.html"),
    distill_path('ageVerification', views.ageVerification, name='ageVerification', distill_func=get_ageVerification),
    distill_path('register', views.register, name="register", distill_func=get_register),
    distill_path('login', LoginView.as_view(template_name='user/login.html'), name='login', distill_func=get_login),
    path('logout', LogoutView.as_view(), name='logout'),
    distill_path('accounts/profile/', views.profile, name="profileUser", distill_func=get_profile),
    distill_path('message/<str:username>', views.message, name="message", distill_func=get_message),
    distill_path('messages', views.messages, name="messages", distill_func=get_messages),
    distill_path('faq', views.faq, name="faq", distill_func=get_faq),
    distill_path('legal', views.legal, name="legal", distill_func=get_legal)
]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
meebcommented, Oct 3, 2020

You do not need to pass in a custom requests object, this is handled for you. However, this view, I suspect, when run via distill won’t do anything. It’ll return a redirect, and probably throw an error for not returning a 200 status code. You can’t distill dynamic actions (decision based redirects, forms, etc.) only static content. For example this will work fine:

def index(request):
    return render(request, "index.html")

But this will not:

def index(request):
    if not request.user.is_authenticated:
        return redirect("/signup")
    return render(request, "index.html")

During building the static site it will always trigger the redirect and result in trying to render a redirect and throwing an error. To make a flat, static site you can only render static views which return HTML and 200 HTTP status code, and it is advisable the views are consistent so always return the same thing when they are called. Obviously a static site can’t support any database or session features at all as no code executes anywhere when looking at a static HTML page.

As for your session error, looks like it could be related to the order of your middleware, does this site work normally without distill under ./manage.py runserver? I’m guessing your ageCheck function tries to set some sort of session variable?

0reactions
meebcommented, Oct 11, 2020

As you’ve not replied for a week I’ll assume this has resolved your issue and close it. Feel free to open another issue if you encounter any more problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - 'WSGIRequest' object has no attribute 'session' while ...
But my MIDDLEWARE classes are in the correct order. INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib ...
Read more >
AttributeError at / 'WSGIRequest' object has no attribute 'session'
locally I was using python 3.5 no virtualenv. Ohhhh. It's because you were using django 1.10 locally and 1.9 on pythonanywhere. One is ......
Read more >
'WSGIRequest' object has no attribute 'session'
Hi,all. I often meet this problem recently while I run the django project. How to fix it? Thanks. Traceback (most recent call last):...
Read more >
'WSGIRequest' object has no attribute 'session' (in webpay)
[traceback] AttributeError: 'WSGIRequest' object has no attribute 'session' (in webpay) · Categories · Tracking · People · References · Details · Crash Data...
Read more >
'WSGIRequest' object has no attribute 'session' #1 - GitHub
I can't reproduce this in development, but in production I get this error when using PinningSessionMiddleware: 'WSGIRequest' object has no attribute ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found