I am willing to save all the http requests to the database (request_method stands for db field) and print them out to the page (for example, last 10 requests) but am getting the following problem: Exception Value: 'WSGIRequest' object has no attribute 'Meta'.
models.py
from django.db import models
class HttpRequest(models.Model):
time = models.DateTimeField(auto_now=True, auto_now_add=False)
request_method = models.CharField(max_length=20)
middleware.py
from .models import HttpRequest
class FirstMiddleware(object):
def process_request(self, request):
data = HttpRequest(request_method=request.Meta['REQUEST_METHOD'])
data.save()
views.py
from django.shortcuts import render
def view_requests(request):
request_list = HttpRequest.objects.all()[:10]
return render(request, 'apps/hello/request_list', {'list': request_list})
This problem occurs during the processing of the middleware.py file (that's why am not sure that view.py is needed here but why not:)) and due to I am a complete beginner in django, it makes a great challenge to fix it by myself, though the task seems to be pretty easy. Would be really glad for you insights.
It's not Meta
. It's META
. Hope this will help you.