title: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f70f408b3c8>: Failed to establish a new connection
body: <p>I am trying to build a social network with django. Every thing was working perfectly. then I changed some code in two views. one in post like_unlike_post view and profile detail view. I added SingleObjectMixin and formviwe with detail view so that people can like and comment on post when visiting others profile. after that I notice this error occurs everytime I try to login or update something. I have no idea what causing this error. Can anyone help me with this. here is my profile detail and update view</p>
  <pre><code>from django.http import HttpResponseRedirect
  from django.contrib.auth import get_user_model
  from django.contrib.auth.mixins import LoginRequiredMixin
  from django.urls import reverse
  from django.shortcuts import get_object_or_404, redirect, render
  from django.utils.translation import gettext_lazy as _
  from django.views import View
  from django.views.generic import DetailView, RedirectView, UpdateView, FormView
  from django.views.generic.detail import SingleObjectMixin
  from .models import Profile
  from posts.forms import PostModelForm, CommentModelForm
  from posts.models import Post
  from relationships.models import Relationship
  
  
  User = get_user_model()
  
  class ProfileDetailView(LoginRequiredMixin, DetailView):
  
      model = Profile
      slug_field = &quot;slug&quot;
      slug_url_kwarg = &quot;slug&quot;
      form_class = CommentModelForm
      queryset = Profile.objects.prefetch_related('posts__likes', 'friends', 'posts__comment_posted', 'posts__comment_posted__user')
  
      def get_context_data(self, **kwargs): 
          context = super().get_context_data(**kwargs)
          
          
          sender_profile = get_object_or_404(Profile, id=self.request.user.id)
          receiver_profile = get_object_or_404(Profile, id=self.object.id)
          frnd_btn_state = Relationship.objects.relation_status(
              sender=sender_profile,
              receiver=receiver_profile,
          )
          context['frnd_btn_state'] = frnd_btn_state
  
          context['frnd_req_rcvd'] = Relationship.objects.invitation_recieved(
              receiver = sender_profile
          )
          context['form'] = CommentModelForm()
          return context
      
  
  class ProfilePostComment(SingleObjectMixin, FormView):
      template_name = 'profiles/profile_detail.html'
      form_class = CommentModelForm
      model = Profile
  
      def post(self, request, *args, **kwargs):
          comment_form = CommentModelForm()
          profile=Profile.objects.get(user=request.user)
          if 'submit_c_form' in request.POST:
              comment_form = CommentModelForm(request.POST or None)
              if comment_form.is_valid():
                  instance = comment_form.save(commit=False)
                  instance.user = profile
                  post_id = request.POST.get('post_id')
                  instance.post = Post.objects.get(id=post_id)
                  instance.save()
                  comment_form = CommentModelForm()
                  return HttpResponseRedirect(self.request.path_info)
  
  
      def get_success_url(self):
          return reverse(&quot;profiles:detail&quot;, kwargs={&quot;slug&quot;: self.request.user.username})         
  
  class ProfileDetailComment(View):
  
      def get(self, request, *args, **kwargs):
          view = ProfileDetailView.as_view()
          return view(request, *args, **kwargs)
  
      def post(self, request, *args, **kwargs):
          view = ProfilePostComment.as_view()
          return view(request, *args, **kwargs)
  
  
  profile_detail_view = ProfileDetailComment.as_view()
  
  class ProfileUpdateView(LoginRequiredMixin, UpdateView):
  
      model = Profile
      fields = [&quot;name&quot;, 'bio', 'gender', 'country', 
          'favourite',
      ]
  
      def get_success_url(self):
          return reverse(&quot;profiles:detail&quot;, kwargs={&quot;slug&quot;: self.request.user.username})
  
      def get_object(self):
          return Profile.objects.get(id=self.request.user.id)
  
      def form_valid(self, form):
          messages.add_message(
              self.request, messages.INFO, _(&quot;Infos successfully updated&quot;)
          )
          return super().form_valid(form)
  
  
  profile_update_view = ProfileUpdateView.as_view()
  
  
  class ProfileRedirectView(LoginRequiredMixin, RedirectView):
  
      permanent = False
  
      def get_redirect_url(self):
          return reverse(&quot;profiles:detail&quot;, kwargs={&quot;slug&quot;: self.request.user.username})
  
  
  profile_redirect_view = ProfileRedirectView.as_view()
  </code></pre>
  <p>And this is my post view which contains post and commenting view and like unlike view</p>
  <pre><code>from django.contrib import messages
  from django.http import HttpResponseRedirect
  from django.contrib.auth.decorators import login_required
  from django.db.models import Q
  from django.db.models import Prefetch
  from django.views.generic import UpdateView, DeleteView
  from django.urls import reverse_lazy
  from .models import Post, Like, Comment
  from profiles.models import Profile
  from .forms import PostModelForm, CommentModelForm
  
  
  
  @login_required
  def post_comment_create_and_list_view(request):
      profile=Profile.objects.get(user=request.user)
      profile_list = Profile.get_all_friends_list(self=request.user)
      #profile contains list of the friends i have
      queryset = Post.objects.all_posts(user_id=request.user.id, profile_list=profile_list)
      
  
      #post form
      post_form = PostModelForm()
      if 'submit_p_form' in request.POST:
          post_form = PostModelForm(request.POST or None, request.FILES or None)
          if post_form.is_valid():
              instance = post_form.save(commit=False)
              instance.author = profile
              instance.save()
              post_form = PostModelForm()
              messages.success(request, 'Post published')
              return redirect('posts:main_post_list')
      
      #comment form
      comment_form = CommentModelForm()
      if 'submit_c_form' in request.POST:
          comment_form = CommentModelForm(request.POST or None)
          if comment_form.is_valid():
              instance = comment_form.save(commit=False)
              instance.user = profile
              post_id = request.POST.get('post_id')
              instance.post = Post.objects.get(id=post_id)
              instance.save()
              comment_form = CommentModelForm()
              return redirect('posts:main_post_list')
  
      context = {
          'queryset': queryset,
          'profile': profile,
          'post_form': post_form,
          'comment_form': comment_form,
      }
      return render(request, 'posts/main.html', context)
  
          
  
  def like_unlike_post(request):
      user = request.user
      print(user)
      if request.method == 'POST':
          post_id = request.POST.get('post_id')
          post_obj = Post.objects.get(id=post_id)
          print(post_obj)
          profile = Profile.objects.get(user=user)
          print(profile)
  
          if profile in post_obj.likes.all():
              print(1)
              post_obj.likes.remove(profile)
          else:
              print(2)
              post_obj.likes.add(profile)
  
          like, created = Like.objects.get_or_create(user=profile, post_id=post_id)
  
          if not created:
              print(3)
              if like.value=='LIKE':
                  print(4)
                  like.value='UNLIKE'
              else:
                  print(5)
                  like.value='LIKE'
          else:
              print(6)
              like.value='LIKE'
  
              post_obj.save()
              like.save()
  
      
  
  
  class PostDeleteView(DeleteView):
      model = Post
      template_name = 'posts/confirm_del.html'
      success_url = reverse_lazy('posts:main_post_list')
  
      def get_object(self, *args, **kwargs):
          id = self.kwargs.get('id')
          obj = Post.objects.get(id=id)
  
          if not obj.author.user == self.request.user:
              messages.warning(self.request, 'You can\'t delete others post!')
              return redirect('posts:main_post_list')
          return obj
  
  class PostUpdateView(UpdateView):
      form_class = PostModelForm
      model = Post
      template_name = 'posts/update.html'
      success_url = reverse_lazy('posts:main_post_list')
  
      def form_valid(self, form):
          profile = Profile.objects.get(user = self.request.user)
          if form.instance.author == profile:
              return super().form_valid(form)
          else:
              form.add_error(None, 'Hey!! You are not the owner of this post!')
              return super().form_invalid(form)
  
  
  class CommentDeleteView(DeleteView):
      model = Comment
      template_name = 'posts/confirm_del.html'
      success_url = reverse_lazy('posts:main_post_list')
  
      def get_object(self, *args, **kwargs):
          id = self.kwargs.get('id')
          obj = Comment.objects.get(id=id)
  
          if not obj.user.user == self.request.user:
              messages.warning(self.request, 'Hey!! You are not the owner of this post!')
              return redirect('posts:main_post_list')
          return obj
  
  class CommentUpdateView(UpdateView):
      form_class = CommentModelForm
      model = Comment
      template_name = 'posts/update.html'
      success_url = reverse_lazy('posts:main_post_list')
  
      def form_valid(self, form):
          profile = Profile.objects.get(user = self.request.user)
          if form.instance.user.id == profile.id:
              return super().form_valid(form)
          else:
              form.add_error(None, 'Hey!! You are not the owner of this post!')
              return super().form_invalid(form)
  </code></pre>
  <p>the error I am getting</p>
  <pre><code>ConnectionError at /accounts/login/
  ConnectionError(&lt;urllib3.connection.HTTPConnection object at 0x7f70f408b3c8&gt;: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(&lt;urllib3.connection.HTTPConnection object at 0x7f70f408b3c8&gt;: Failed to establish a new connection: [Errno 111] Connection refused)
  Request Method: POST
  Request URL:    http://localhost:8000/accounts/login/
  Django Version: 3.0.10
  Exception Type: ConnectionError
  Exception Value:    
  ConnectionError(&lt;urllib3.connection.HTTPConnection object at 0x7f70f408b3c8&gt;: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(&lt;urllib3.connection.HTTPConnection object at 0x7f70f408b3c8&gt;: Failed to establish a new connection: [Errno 111] Connection refused)
  Exception Location: /home/sddhruvo/Desktop/django/stalker/env/lib/python3.7/site-packages/elasticsearch/connection/http_urllib3.py in perform_request, line 124
  Python Executable:  /home/sddhruvo/Desktop/django/stalker/env/bin/python
  Python Version: 3.7.3
  Python Path:    
  ['/home/sddhruvo/Desktop/django/stalker/stalker_project',
   '/usr/lib/python37.zip',
   '/usr/lib/python3.7',
   '/usr/lib/python3.7/lib-dynload',
   '/home/sddhruvo/Desktop/django/stalker/env/lib/python3.7/site-packages',
   '/home/sddhruvo/Desktop/django/stalker/stalker_project/stalker_project',
   '/home/sddhruvo/Desktop/django/stalker/stalker_project/stalker_project']
  Server time:    Sat, 26 Sep 2020 12:26:55 +0000
  </code></pre>