Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:32:24+00:00 2026-06-12T05:32:24+00:00

Everything works correctly apart from redirecting back to the index page after adding the

  • 0

Everything works correctly apart from redirecting back to the index page after adding the products data, currently after my data gets save it gets redirected to 127.0.0.1:8000/product/add_product/add_product

Currently when my index page(add_product.html) loads, I have a table that renders data from the database,

  1. first my url looks like >> 127.0.0.1:8000/product/
  2. Then once I hit the add button url changes to 127.0.0.1:8000/product/add_product/ , no problem there, but
  3. when i try to add data again my url goes to 127.0.0.1:8000/product/add_product/add_product and i get a Page not found error

My views.py

from models import Product,Category
from django.shortcuts import render_to_response,get_object_or_404
from django.http import HttpResponseRedirect

def index(request):
    category_list = Category.objects.all()
    product_list = Product.objects.all()
    return render_to_response('product/add_product.html', {'category_list': category_list, 'product_list':product_list})

def add_product(request):
    post = request.POST.copy()

    category = Category.objects.get(name=post['category'])
    product = post['product']
    quantity = post['quantity']
    price = post['price']

    new_product = Product(category = category, product = product, quantity = quantity, price = price )
    new_product.save()
    category_list = Category.objects.all()
    product_list = Product.objects.all()
    return render_to_response('product/add_product.html', {'category_list': category_list, 'product_list':product_list})

My urls.py

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns('product.views',
    url(r'^$', 'index'),                       
    url(r'^add_product/$', 'add_product'),
)

How do i get the URL pointing back to my index page(add_product.html) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:32:25+00:00Added an answer on June 12, 2026 at 5:32 am

    In the view of 127.0.0.1:8000/product/add_product/ return this

    from django.http import HttpResponseRedirect
    
    def add_product(request)
        ...........................
        ...........................
        return HttpResponseRedirect('/')
    

    It will redirect to index page.
    Also try to give url name so that you can use reverse instead of ‘/’

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using automatic conversion from wsdl to c#, everything works apart from encoding, whenever
I am currently trying to use this gem http://github.com/pengwynn/linkedin . Everything works fine (i.e.
I currently have a thread that I created using CreateRemoteThread(). Everything works great. Upon
I'm currently working on a Perl script to gather data from the QuakeLive website.
When I open an NSWindow which is autoreleased, everything works correctly. The NSWindow is
I created a drop down nav menu purely in css and everything works correctly
Confusion On my emulator everything works correctly, the dialog comes up and works perfectly.
I'm currently busy making a Python ORM which gets all of its information from
I am developing my own forums and everything is working perfectly apart from when
With 2 columns, everything works correct, all the background in the TreeView is white.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.