# failing to redirect

**URL:** <https://forum.djangoproject.com/t/failing-to-redirect/22236>\
**Category:** Getting Started\
**Created:** [July 12, 2023, 7:39am UTC](https://forum.djangoproject.com/t/failing-to-redirect/22236 "2023-07-12T07:39:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mukelabai01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mukelabai01/32/14480_2.png) [@Mukelabai01](https://forum.djangoproject.com/u/Mukelabai01)\
**Post date:** [July 12, 2023, 7:39am UTC](https://forum.djangoproject.com/t/failing-to-redirect/22236/1 "2023-07-12T07:39:57Z")

</div>

when a user submits the form, it does not redirect the user to the success page nor does it bring any message indcating that one has successfully created an appointment. Note that the information is properly being saved in the database.  
my views

```auto
from pyexpat.errors import messages
from django.shortcuts import redirect, render
from django.http import HttpResponse
from django.contrib import messages
from .forms import AppointmentForm
from .models import *
from django.core.mail import send_mail
from datetime import datetime
from django import forms
from django.core.exceptions import ValidationError
from django.utils.dateparse import parse_date, parse_time
from django.http import HttpResponseRedirect
from django.urls import reverse

# Create your views here.
def home(request):
   form = AppointmentForm() # Create an instance of the form
   return render(request, 'index.html', {'form': form})

def about(request):
   return render(request,'about.html')

def services(request):
   return render(request,'services.html')

def pricing(request):
   return render(request,'pricing.html')

def contact(request):
   return render(request,'contact.html')

def appointment(request):
   return render(request, 'appointment.html') 

def success_view(request):
   return render(request, 'success.html')   
  
def store(request):
   return render(request, 'store.html')

def create_appointment(request):
   if request.method == 'POST':
       form = AppointmentForm(request.POST)
       if form.is_valid():
           form.save()
           # Log the form data
           print(form.cleaned_data)
           messages.success(request, 'Appointment created successfully.')
           return HttpResponseRedirect('/success/') 
       else:
           messages.error(request, 'Error submitting the form. Please check the entered data.')
   else:
       form = AppointmentForm()

   return render(request, 'index.html', {'form': form})

my urls
from django import views
from django.urls import path
from .views import *

urlpatterns = [
   path('', home, name='home'),
   path('about/', about, name='about'),
   path('services/', services, name='services'),
   path('pricing/', pricing, name='pricing'),
   path('contact/', contact, name='contact'),
   path('success/', success_view, name='success_view'),
   path('create_appointment/', create_appointment, name='create_appointment'),
   
   
   
  
]

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 12, 2023, 11:15am UTC](https://forum.djangoproject.com/t/failing-to-redirect/22236/2 "2023-07-12T11:15:49Z")

</div>

I’m a little confused by what you have posted here.

What’s the purpose of this `home` view? How does this differ from the `create_appointment` view? (Why do you appear to have two views showing the same template with the same form?)

What does the `form` tag look like in your `index.html` template?

---

<div class="post-metadata">

**Author:** ![Mukelabai01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mukelabai01/32/14480_2.png) [@Mukelabai01](https://forum.djangoproject.com/u/Mukelabai01)\
**Post date:** [July 12, 2023, 12:30pm UTC](https://forum.djangoproject.com/t/failing-to-redirect/22236/3 "2023-07-12T12:30:22Z")

</div>

i experienced an error earlier, where if i click on make an appointment in my browser on [http://127.0.0.1:8000](http://127.0.0.1:8000)(index.html) the form would not load but when i enter [http://127.0.0.1:8000/create\_appointment](http://127.0.0.1:8000/create_appointment) the form would load. so i made modifications to my views for the form to load on [http://127.0.0.1:8000/](http://127.0.0.1:8000/) when i want to reach it instead of me having to type [http://127.0.0.1:8000/create\_appointment](http://127.0.0.1:8000/create_appointment) in my browser

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 12, 2023, 1:02pm UTC](https://forum.djangoproject.com/t/failing-to-redirect/22236/4 "2023-07-12T13:02:06Z")

</div>

Then have your “empty” url run the `create_appointment` view instead of `home`.

---

<div class="post-metadata">

**Author:** ![Mukelabai01](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mukelabai01/32/14480_2.png) [@Mukelabai01](https://forum.djangoproject.com/u/Mukelabai01)\
**Post date:** [July 12, 2023, 1:04pm UTC](https://forum.djangoproject.com/t/failing-to-redirect/22236/5 "2023-07-12T13:04:45Z")

</div>

how do you mean sir?, and will that solve the redirect issue i am facing?
