AttributeError: 'Request' object has no attribute 'post'
AttributeError: 'Request' object has no attribute 'app' - - -
'HttpRequest' object has no attribute 'META'
'Application' object has no attribute 'request'
I have this idea to put a confirm/deny in list_page so that when I click confirm it automatically sends an email to the user that he or she is approved. I have put a confirm/deny in list_page successfully, but it gives me an attribute error when I click confirm. Can someone help me what's wrong with my code?
this is my views
@admin.register(Application)
class ApplicationAdmin(admin.ModelAdmin):
list_display = ['user', 'confirmed', 'denied']
def confirmed(self, obj):
url = reverse('admin:confirm_url', kwargs={'id': obj.id})
return format_html('<a class="button" href="{}">Confirm</a>', url)
def denied(self, obj):
url = reverse('admin:denied_url', kwargs={'id': obj.id})
return format_html('<a class="button" href="{}">Deny</a>', url)
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('confirm/<int:id>', self.confirmed_application, name='confirm_url'),
path('deny/<int:id>', self.denied_application, name='denied_url'),
]
return custom_urls + urls
def confirmed_application(self, request, id):
# you get object_id you can do whatever you want
# you can send a mail
self.object = self.get_object(request, id)
subject = 'Approved'
message = f'Your application has been approved.'
email_from = settings.EMAIL_HOST_USER
recipient_list = [self.request.user.email]
send_mail(subject, message, email_from, recipient_list)
# after processed all logic you can redirect same modeladmin changelist page
redirect_url = "admin:{}_{}_changelist".format(self.opts.app_label, self.opts.model_name)
return redirect(reverse(redirect_url))
def denied_application(self, request, id):
# same as confirmed_application
self.object = self.get_object(request, id)
subject = 'Rejected'
message = f'Your application has been denied.'
email_from = settings.EMAIL_HOST_USER
recipient_list = [self.request.user.email]
send_mail(subject, message, email_from, recipient_list)
redirect_url = "admin:{}_{}_changelist".format(self.opts.app_label, self.opts.model_name)
return redirect(reverse(redirect_url))The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error.
Import urllib.request instead of urllib.
import urllib.request
Interestingly, I noticed some IDE-depending behavior.
Both Spyder and PyCharm use the same interpreter on my machine : in PyCharm I need to do
import urllib.request
while in Spyder,
import urllib
does fine
Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
If you’re using python 3+ this may also occur if you’re using private variables that start with double underscore, e.g., self.__yourvariable. Just something to take note of for some of you who may run into this issue.