Sunday, February 26, 2012

Re: Using query set in views.py

Ok disregard my previous question.

Here's the latest one.


I have the following form in my HTML:
<form method="POST" id="keywordForm" action="/keyword_subscribe/">
<label>Keyword: </label>
<input id="myTextField" type="text" size="50" value="Enter a new keyword for rosebud to crawl!">
</br>
<input type="submit" value="Submit" />
</form>

when the user presses the submit button, it will go to the method keyword_subscribe in views.py


The method is as shown:

def keyword_subscribe(request):
    if request.POST:
username = UserProfile.objects.all()
#userid = username.objects.all()
    subscription_days = "7"
new_keyword = request.POST.get('myTextField')
print new_keyword
    new_keyword_subscribed = subscribe_keyword(username,subscription_days,new_keyword)        
                                                
        response = simplejson.dumps({'new_keyword': new_keyword_subscribed})       
print new_keyword_subscribed                                      
    else:
       # html = form.errors.as_ul()
        response = simplejson.dumps({'success':'False'})
return HttpResponseRedirect("/accounts/login/")
    #if request.is_ajax():
     #   return HttpResponse(response, mimetype='application/json')
    #else:
     #   return HttpResponseRedirect("/")

Once in this method, i'm supposed to extract the word which the user entered in the textfield and store it in a variable called new_keyword

However, i've been getting NONE which means there's something wrong somewhere and i do hope someone can help me.

In addition, i would like to get the username which is stored in the UserProfile table in my database to be passed as a parameter to the next function too.

How then do i implement the queryset needed?

This should be clearer. 

Thank you.


Best Regards,

Stanwin Siow



On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:

Your question is not at all clear. You can use whatever you like in your view. What problem are you having?
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/1N2Cz2nv9wQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


No comments:

Post a Comment