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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:05:36+00:00 2026-06-07T09:05:36+00:00

I’m not really too sure how to title this question, but I’m trying to

  • 0

I’m not really too sure how to title this question, but I’m trying to develop a simple webapp with Django. What I’m trying to do is that the user will manually tag each image, and each tag will have a foreign key to a specific image (but each image can have multiple tags). The index page is supposed to display the actual image, but I haven’t figured that out yet…

Pretty much the problem is, I’m not sure how to implement it so for each page, the index page will show a picture and a box for the image tag. After the user submits, it will go to the next untagged image / image with the least number of tags. Right now, the user can submit a tag (and the data is written correctly), but it still stays on the same image. I’m a Python / Django noob, so forgive me 😛

Here is the relevant source code:

forms.py:

class InputForm(forms.ModelForm):
image = forms.ModelChoiceField(queryset=Image.objects.all(),
    widget=forms.HiddenInput())

class Meta:
    model = Tag 

models.py:

class Image(models.Model):
image_location = models.CharField(max_length=200)
num_tags = models.IntegerField(default=0)   
image_score = models.FloatField()   
def __unicode__(self):
    return u'%d' % self.id 

class Tag(models.Model):
image = models.ForeignKey(Image)
tag_text = models.CharField(max_length=200, blank=True)

def __unicode__(self):
    return self.tag_text

views.py:

def index(request):
    if request.method == 'POST':
            return HttpResponse(request.POST['image'])

    image = Image.objects.all()[0]
    form = InputForm(initial={'image': image})
    return render_to_response('imageSite/index.html',
    {
            'form':form,
    },
    context_instance=RequestContext(request))

def submit(request):
    form = InputForm(request.POST)
    if(form.is_valid()):
            image = form.cleaned_data['image'];
            image.num_tags = image.num_tags + 1
            image.save()
            model = form.save()
            model.save()
            return redirect(index)

index.html:

<ul>
<form action="/imageSite/submit/" method="post">
{%csrf_token %}
<table>
    {{ form.as_table }}
</table>    
<input type="submit" value="Submit" /> 
</form> 
</ul>
  • 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-07T09:05:37+00:00Added an answer on June 7, 2026 at 9:05 am

    The code return redirect(index) won’t work. You’ll need to return a redirect response with the proper URL to which it should redirect. For example:

    redirect_url = '/images/45/'
    return HttpResponseRedirect(redirect_url)
    

    See this example in the Django documentation for a full example. Note that the value for redirect_url needs to be computed in your view: you’ll need to compute the Image object with the least number of tags and use Django’s reverse to cleanly compute the URL of that Image object. If the form is invalid then you should not perform a redirect.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but

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.