No connection could be made because the target machine actively refused it (Django)

前端 未结 7 786
小鲜肉
小鲜肉 2021-02-07 12:14

I have followed the Django Book up until chapter seven, and I am currently messing around with forms, GET, POST and all that goodness. At one point, the guide made me figure out

相关标签:
7条回答
  • 2021-02-07 12:49

    I've never used DJango myself but judging by the error, there is no server listening at port 8000 (or some firewall/server restriction is blocking port 8000 on localhost)

    0 讨论(0)
  • 2021-02-07 12:52

    10061 isn't the port number, that's the error number. You want to open port 8000.

    See this answer for someone who was having the same problem because they were using the wrong port: No connection could be made because the target machine actively refused it

    0 讨论(0)
  • 2021-02-07 12:56

    I got this error attempting to use django.core.mail.send_mail. I only need this for running through some tutorials. I don't need it to actually send mail.

    The solution for me was to add this single variable to settings.py:

    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
    

    It sends the content of the email to console output, which is perfect given what I'm doing.

    Docs: https://docs.djangoproject.com/en/1.7/topics/email/#django.core.mail.backends.smtp.EmailBackend

    0 讨论(0)
  • 2021-02-07 13:02

    In settings.py, For console output, you need

    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
    

    For smtp

    EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
    

    Also refer this doc here https://docs.djangoproject.com/en/1.6/topics/email/

    0 讨论(0)
  • 2021-02-07 13:03

    I managed to find out what the problem was (no thanks to the error message). As it turns out, I needed to set up my e-mail server:

    Note that in order to send e-mail using send_mail(), your server must be configured to send mail, and Django must be told about your outbound e-mail server. See http://docs.djangoproject.com/en/dev/topics/email/ for the specifics.

    I guess I thought little of what was meant by it, but I was pointed in the direction of this guide, and things eventually started to click.

    Thanks to everyone for chiming in with their advice. That is one useless error message, and I can only assume the people who helped me out only knew the answer because they had experienced the exact same thing.

    0 讨论(0)
  • 2021-02-07 13:05

    The code tries to connect to http://127.0.0.1:8000/contact/ - the port 8000 is not reachable (firewall) or there is no server running.

    0 讨论(0)
提交回复
热议问题