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 7973597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:09:02+00:00 2026-06-04T08:09:02+00:00

I already used the answer to this question , but for some reason I’m

  • 0

I already used the answer to this question, but for some reason I’m not getting a good result.

I’m trying to use the same template for my edit form and my add form. Here’s my urls.py:

url(r'^app/student/new/$', 'edit_student', {}, 'student_new'),
url(r'^app/student/edit/(?P<id>\d+)/$', 'edit_student', {}, 'student_edit'),

And my views.py:

def edit_student(request, id=None, template_name='student_edit_template.html'):
if id:
    t = "Edit"
    student = get_object_or_404(Student, pk=id)
    if student.teacher != request.user:
        raise HttpResponseForbidden()
else:
    t = "Add"
    student = Student(teacher=request.user)

if request.POST:
    form = StudentForm(request.POST, instance=student)
    if form.is_valid():
        form.save()

        # If the save was successful, redirect to another page
        redirect_url = reverse(student_save_success)
        return HttpResponseRedirect(redirect_url)

else:
    form = StudentForm(instance=student)

return render_to_response(template_name, {
    'form': form,
    't': t,
}, context_instance=RequestContext(request))

And my forms.py:

class StudentForm(ModelForm):
class Meta:
    model = Student
    exclude = ('teacher',)

And finally my template student_edit_template.html:

<h1>{{ t }} Student</h1>
<form action="/app/student/edit/{{ student.id }}" method="post"> {% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>

For some reason, this is throwing a 404:

Page not found (404)
Request Method: POST
Request URL:    http://192.168.1.3:5678/app/student/edit/

I’m probably missing something easy here, but at this point I need another set of eyes on it at the very least.

Thanks in advance!

  • 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-04T08:09:04+00:00Added an answer on June 4, 2026 at 8:09 am

    You’re getting the 404 because /student/edit/ requires an id at the tail end otherwise there’s no route, and when you’re coming from /student/new/ you don’t have an id yet. Create a route and view for /student/edit/ and put logic in there to handle the case for when you’re creating a record on POST.

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

Sidebar

Related Questions

I half realize that this question is probably asked already, but I'm not familiar
I used to configure boost already, but this time I have no idea what
I know this question has already been asked but I am in urgent need
Quick question; I've googled around and found some answers already, but I'm a bit
May be some body already used some open source component, writing on jquery. And
sending mail along with embedded image using asp.net I have already used following but
Already found this page with some helpful hints. Problem is I need to debug
This question came into my mind while generating sample data for a SO-answer. I
I have not used PackedArray before, but just started looking at using them from
First of all I alwyas use one #ID. just asking this question to know

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.