Re: How can I parse and process the contents of an URL?
Wondering if you were able to solve this one? Trying something similar, can you post the rest of the source, I'm a newb, thankyou lg On Jan 28, 11:19 pm, Michael Elsdörfer <[EMAIL PROTECTED]> wrote: > > but the page seems to load forever and I'm stuck! > > I'm pretty sure I ran into this before, and IIRC it's because Django's > runserver, which I assume you are using, can only handle one request at > a time - try a different test url. > > Michael > > MariusB schrieb: > > > I'm trying to take a link as an argument, open it, read it's content > > and then display the first 50 characters from it. First of all, I've > > tried to put the code in the views.py, but I didn't make it. Now I > > made a middleware component with this code: > > > import urllib2 from django.shortcuts import render_to_response > > > TEST_URL = 'http://127.0.0.1:8000/openurl/' > > > class Char50(object): def process_view(self, request, view_func, > > view_args, view_kwargs): query = request.POST.get('q', '') c = > > urllib2.urlopen(TEST_URL) contents = c.read( ) conturl = > > contents[0:50] return render_to_response("test.html", { "query": > > query, "results": conturl }) > > > but the page seems to load forever and I'm stuck! I've read the > > chapters from the djangobook, searched on the Internet, but I still > > haven't found a solution. > > > Please help me! > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Javascript, Access Radio Button Elements
Hi, I have a form definition for two radio buttons named choices. I want to loop through the radio buttons to perform a check with javascript in the rendered html page, however due to the radio button _id's that are rendered by the template, I cannot access them with javascript using getElementById(). Wondering if anyone can suggest how to solve this? My form definition contains: choices = forms.ChoiceField(label='Choices', required=True, widget=forms.RadioSelect, choices=options) options = (('good', 'Good'), ('bad', 'Bad')) The rendered html is as follows: Choices: Good Bad My Javascript function is passed an object obj which contains a choices paramater. obj.choices will be either "good" or "bad" so I would normally be able to set it based on what is passed. My normal approach would be to check the current setting by using getElementById, then comparing to what is passed from obj.choices and if equal, setting the relevant radio. As I have two id's id_choices_0 and id_choices_1 I'm guessing that I can't use id_choices_0 in getElementById as in previous worlds. Before Django my radio buttons would only have one id which I would use to reference. for (var i=0; i < document.getElementById('id_choices_0').length; i++) { if (document.getElementById(id_choices_[i]).value == obj.choices) document.getElementById(id_choices_[i]).checked = true; } Can anyone help? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Javascript, Access Radio Button Elements
Thanks Daniel, Worked a treat, had tried something similar but for some reason it complained. This way worked fine. On Feb 21, 8:54 pm, Daniel Roseman <[EMAIL PROTECTED]> wrote: > On 21 Feb, 18:57, Little_Grungy <[EMAIL PROTECTED]> wrote: > > > > > Hi, > > > I have a form definition for two radio buttons named choices. I want > > to loop through the radio buttons to perform a check with javascript > > in the rendered html page, however due to the radio button _id's that > > are rendered by the template, I cannot access them with javascript > > using getElementById(). Wondering if anyone can suggest how to solve > > this? > > > My form definition contains: > > > choices = forms.ChoiceField(label='Choices', required=True, > > widget=forms.RadioSelect, choices=options) > > options = (('good', 'Good'), ('bad', 'Bad')) > > > The rendered html is as follows: > > > > > Choices: > > > > > > > > > > > >> value="good"/> > > Good > > > > > > > > > > > > Bad > > > > > > > > > My Javascript function is passed an object obj which contains a > > choices paramater. obj.choices will be either "good" or "bad" so I > > would normally be able to set it based on what is passed. My normal > > approach would be to check the current setting by using > > getElementById, then comparing to what is passed from obj.choices and > > if equal, setting the relevant radio. > > > As I have two id's id_choices_0 and id_choices_1 I'm guessing that I > > can't use id_choices_0 in getElementById as in previous worlds. Before > > Django my radio buttons would only have one id which I would use to > > reference. > > > for (var i=0; i < document.getElementById('id_choices_0').length; i++) > > { > > if (document.getElementById(id_choices_[i]).value == obj.choices) > > document.getElementById(id_choices_[i]).checked = true; > > } > > > Can anyone help? > > It's not Django that's the problem, it's the javascript. Why not try > something like this (untested): > > var choice; > var choice_length = 2; > for (var i=0; i < choice_length; i++) > { > choice = document.getElementById('id_choices_' + i); > if (choice.value == obj.choices) > { > choice.checked = true; > } > > } > > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---