0

after submiting form and POST method I have warnings in my console, and I don't know what to fix. Any idea?

[19/Dec/2019 12:13:25] "GET /scenario/14/ HTTP/1.1" 200 7573
C:\django\ENV\lib\site-packages\django\db\models\fields\__init__.py:1364: RuntimeWarning: DateTimeField Comment.commentDate received a naive datetime (2019-12-19 12:13:28.699121) while time zone support is active.
  RuntimeWarning)
Internal Server Error: /comment/14/
Traceback (most recent call last):
  File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 116, in get_success_url
    url = self.object.get_absolute_url()
AttributeError: 'Comment' object has no attribute 'get_absolute_url'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\django\ENV\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\django\ENV\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\django\ENV\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\django\ENV\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\django\ENV\lib\site-packages\django\contrib\auth\mixins.py", line 52, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "C:\django\ENV\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 172, in post
    return super().post(request, *args, **kwargs)
  File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 142, in post
    return self.form_valid(form)
  File "C:\django\m\testmanager\views.py", line 58, in form_valid
    return super().form_valid(form)
  File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 126, in form_valid
    return super().form_valid(form)
  File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 57, in form_valid
    return HttpResponseRedirect(self.get_success_url())
  File "C:\django\ENV\lib\site-packages\django\views\generic\edit.py", line 119, in get_success_url
    "No URL to redirect to.  Either provide a url or define"
django.core.exceptions.ImproperlyConfigured: No URL to redirect to.  Either provide a url or define a get_absolute_url method on the Model.
[19/Dec/2019 12:13:28] "POST /comment/14/ HTTP/1.1" 500 108634
[19/Dec/2019 12:13:28] "GET /scenario/14/ HTTP/1.1" 200 7679
Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 332, in send_headers
    self.send_preamble()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 255, in send_preamble
    ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 453, in _write
    result = self.stdout.write(data)
  File "c:\program files (x86)\python37-32\Lib\socketserver.py", line 799, in write
    self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] Nawiązane połączenie zostało przerwane przez oprogramowanie zainstalowane w komputerze-hoście
[19/Dec/2019 12:13:28] "POST /comment/14/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 61435)
Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 138, in run
    self.finish_response()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 332, in send_headers
    self.send_preamble()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 255, in send_preamble
    ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 453, in _write
    result = self.stdout.write(data)
  File "c:\program files (x86)\python37-32\Lib\socketserver.py", line 799, in write
    self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] Nawiązane połączenie zostało przerwane przez oprogramowanie zainstalowane w komputerze-hoście

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 141, in run
    self.handle_error()
  File "C:\django\ENV\lib\site-packages\django\core\servers\basehttp.py", line 119, in handle_error
    super().handle_error()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 368, in handle_error
    self.finish_response()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 180, in finish_response
    self.write(data)
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 274, in write
    self.send_headers()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files (x86)\python37-32\Lib\socketserver.py", line 650, in process_request_thread
    self.finish_request(request, client_address)
  File "c:\program files (x86)\python37-32\Lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "c:\program files (x86)\python37-32\Lib\socketserver.py", line 720, in __init__
    self.handle()
  File "C:\django\ENV\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
    self.handle_one_request()
  File "C:\django\ENV\lib\site-packages\django\core\servers\basehttp.py", line 197, in handle_one_request
    handler.run(self.server.get_app())
  File "c:\program files (x86)\python37-32\Lib\wsgiref\handlers.py", line 144, in run
    self.close()
  File "C:\django\ENV\lib\site-packages\django\core\servers\basehttp.py", line 114, in close
    super().close()
  File "c:\program files (x86)\python37-32\Lib\wsgiref\simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'

My CreateView:

class CommentCreateView(LoginRequiredMixin, CreateView):
    model = Comment
    fields = [
        'commentText'
    ]

    def form_valid(self, form):
        form.instance.commentAuthor = self.request.user
        form.instance.commentDate = datetime.now()
        form.instance.commentScenario = Scenario.objects.get(pk=self.kwargs.get('scenario_id'))
        return super().form_valid(form)

and form:

<form method="POST" action="{% url 'comment-create' scenario.pk %}" onsubmit="setTimeout(function(){window.location.reload();},10)">
    {% csrf_token %}
    {{ newComment }}
    <div class="center">
        <button class="btn waves-effect waves-light" type="submit"value="Submit">Publish</button>
    </div>
</form>
lukos06
  • 187
  • 1
  • 4
  • 20
  • Are you worried about the timezone warning or the 500 errors/stack traces that you pasted? The two are entirely unrelated. – wholevinski Dec 19 '19 at 12:43
  • Especially this ```AttributeError: 'NoneType' object has no attribute 'split'``` and ```AttributeError: 'Comment' object has no attribute 'get_absolute_url'``` – lukos06 Dec 19 '19 at 12:46
  • Those are happening further down when trying to handle the original exception that's raised. You need to look at the original exception and start from there. This is the issue: `AttributeError: 'Comment' object has no attribute 'get_absolute_url'`. You need to define that function on your `Comment` model. See here: https://docs.djangoproject.com/en/3.0/ref/models/instances/#get-absolute-url – wholevinski Dec 19 '19 at 12:48
  • See this answer as well. It might be helpful: https://stackoverflow.com/questions/16004679/django-class-based-views-get-absolute-url-not-working – wholevinski Dec 19 '19 at 12:50
  • Ok, I added ```def get_absolute_url(self): return reverse('scenario-detail', kwargs={'pk': self.pk})``` to my ```models.py``` and this warning no longer exist. But what now with this ```AttributeError: 'NoneType' object has no attribute 'split'``` and all of 500? Any sugestions? – lukos06 Dec 19 '19 at 12:54

0 Answers0