Re: how to add login info while opening url
mm..I tried that..it gives 403 error.. I don't think putting login info in request will help..that will work only for 401 I believe.. not sure how to handle 403 from server..Any comments guys? harry On Oct 12, 6:19 pm, jimgardener wrote: > hi > I was trying to get data from different web pages using urlopen and > read. > > from urllib import urlopen > def get_page_data(url): > f=urlopen(url) > return f.read() > > when I gave this url ,it produces a 'forbidden' response > > print get_page_data('http://groups.google.com/group/django-users/ > topics') > > ==> > > ... > Forbidden > Your client does not have permission to get URL /group/django- > users/topics from this server. > ... > > I understand that it needs my login info..In a client program ,how do > I add this?My django app maintains a list of urls entered by a user > and at a user given time opens and reads from each of the urls.In the > db I am storing the url string ,a user object and a datetime value > entered by the user .Suppose one of those urls needs login info as in > the above case,how can I store those?The same user may have different > login username,passwords for different urls.I don't think storing user > password in db is a good idea.. > Is there a way to deal with this? > Any suggestions? > regards > jim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: trouble creating first project
do you have django_settings_module set?if so you will get this error http://code.djangoproject.com/ticket/11980 otherwise it is a path problem HTH harry On Oct 11, 6:47 am, Phil wrote: > Hi, > > I am having trouble creating my first project. I am running the latest > version of Ubuntu and I installed Django from svn, when I run 'import > django' i get no errors back so I assume its installed OK. > > When I run 'django-admin.py startproject myproject' I get back an > error saying 'django-admin.py: command not found'. > > How can I solve/get around this error? Appreciate any help/ advice > offered -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to prevent different instances with same state
I have a model called Tracker that has a User and a url .I need User- url combination to be unique.So I made classTracker(models.Model): url=models.URLField() owner=models.ForeignKey(User) class Meta: unique_together = (("owner", "url"),) Now,I need to create a TrackingUtility that takes a Tracker object and does some processing using the data at the url. class TrackingUtility: def __init__(self,tracker): self.url=self.tracker.url self.owner=self.tracker.owner def do_something(self): I need to make sure that only one instance of TrackingUtility with the given tracker object exists.I mean if a client calls , user1=User.objects.get(id=1) user2=User.objects.get(id=2) tr1=Tracker(user1,'url1') trackutil1=TrackingUtility(tr1) trackutil2=TrackingUtility(tr1) then there should only be one TrackingUtil object with Tracker of user1 and 'url1' .How do I ensure this? Any suggestions most welcome. thanks, harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: treating different versions of website urls as one
The user can enter a website address which will be tracked by the program for certain info and then a message is sent to the user's mail.The user can enter many such addresses.The problem is that he may accidently enter different variations of the url..and if I don't validate it for duplicates ,the program will be doing the same work again unnecessarily. if user gives http://www.djangocon.us and djangocon.us or http://djangocon.us ,the program will use those in urllib.urlopen(urlstring) ,and the read page /data will be the same. .This is why I need to consider the validation for duplicates thanks for the replies harry On Oct 5, 10:00 pm, Steve Holden wrote: > What aboutwww.mysite.com/default.asp?It might be helpful if you could > give us a little more insight into the real requirement here, rather > than a technical question based on some interpretation of the requirement. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
treating different versions of website urls as one
hi I am trying out a web app where it needs to process user given website addresses .My problem is that ,I need to treat http://mysite.com , www.mysite.com, mysite.com, www.mysite.com/index.html, www.mysite.com/index.php ...etc as the same and not different urls.How can I do the validation in this case?Do I have to manually do the string parsing and validate? Any suggestions most welcome thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: notification in python
hi Erik that was food for thought..content length may not work if substitutions leave length unchanged.. Will look into L distance ..thanks for the suggestion regards harry > Content length (which you could also get using the HTTP header "Content > Length") won't necessarily tell you if content has changed. I think your > problem is a candidate > forhttp://en.wikipedia.org/wiki/Levenshtein_distance(calculating the > "distance" between two strings), for which I think there are Python > implementations. > > Depending on your requirements, you could add other heuristics to detect > major changes, e.g. load the page into an XML parser and only check certain > 's. But further suggestions would require more information on your > problem. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: notification in python
> You could also try looking at the HTTP headers for a request for e.g. > "index.htm" using urllib. Specifically the "Expires" and "Last-Modified". > Using headers values requires that you can trust the site on the header > content. Web servers and caching proxies can do all sorts of things with the > headers. Otherwise, saving the hash of the raw HTML (without GIFs etc.) as > suggested is a good approach. Depending on what your definition of "updated" > is. > thanks Erik, By 'update' I meant a major addition/removal of text(say 100 characters). Initially I thought of making hash of a page and comparing it to the saved hash of the same page at a different moment of time..But ,this would cause even a tiny change to be considered as an update..I would like to use a filter to set an update of x number of characters. May be using f=urllib.urlopen and currentsize=len(f.read()) will let me find the number of added/ removed characters..and set the filter accordingly.. any other suggestions most welcome harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: notification in python
thanks for the pointer I am trying to get something similar to changedetection but with hourly updates. I need to get updates from a number of sites..So I was wondering how to implement an updating utility harry On Sep 27, 9:16 pm, Shawn Milochik wrote: > If you're asking for functionality like this:http://www.changedetection.com/ > > Or are you looking for something to embed in your own code to know when > something has happened on your own site? > > If the former, you can probably do it by scheduling a urlopen and saving its > hash, comparing it each time. If the latter, you can use the logging module. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
notification in python
hi Is there an opensource notification utility in python/django?I mean, something I can use to know when a website updates a page? If someone knows about one,please let me know thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to check size of a dict or list in template
> I would try with > > {%if not object_status.0 %} > hi thanks.That was quite new to me..can you tell me how that works? I also tried {% if not objects_status.items|length_is:"0" %} thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to check size of a dict or list in template
hi I am passing a dictionary to the template say, objects_status={obj1:True, obj2:False, obj3:True } In the template I want to show something like {%if not len(objects_tatus ) %} # just to clarify the purpose..I know len will not work No objects to show {% else %} Objects are: . {%endif %} But how can I check the size of the dictionary? If it was a Queryset I could have used qset.count ..but here it would not work. Can somebody help? thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
checking size of dict or list in template
hi I am passing a dictionary to the template say, objects_status={obj1:True, obj2:False, obj3:True } In the template I want to show something like {%if not len(objects.status ) %} # just to clarify the purpose..I know len will not work No objects to show {% else %} Objects are: .show the objects and truth values in a table {%endif %} But how can I check the size of the dictionary? If it was a Queryset I could have used qset.count ..but here it would not work. Can somebody help? thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to capture the exception
sorry, missed while copying def save(self): self.name=self.name.strip() if (not self.pk): if Article.objects.filter(name__iexact=self.name).count()! =0: raise Exception('article exists..') this causes 500 error,and causes the traceback displayed on browser..how can I prevent this crash and give the user some useful warning? .harry (sorry for the noob qn) On Feb 25, 12:57 am, Shawn Milochik wrote: > Note: > > As written, your code will never let you edit an existing Article. You should > add an if statement to check whether 'self.pk' is true also. > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to capture the exception
hi In my models save() method I want to check if an Article with same name already exists. class Article(Model): name=models.CharField(max_length = 1024, unique = True) def save(self): self.name=self.name.strip() if Article.objects.filter(name__iexact=self.name).count()!=0: raise Exception('article with name %s already exists'%self.name) When I create an article thru a ModelForm and give an existing article's name ,it raises an exception and causes 500 server error.I want to catch this exception and display an error message instead of letting the program crash.Can someone tell me how and where I can do this?Should I do this in the view? thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to populate a forms.Form from existing values.
hi I am learning the use of Forms and tried populating a form from an instance.Here I encountered a problem. I have a class Lecture which can belong to diff subjects.So I created a field 'subjects' in Lecture to be a ManyToManyField. For example, Lecture1 -data structures,algorithms Lecture2 -data structures,c programming Lecture3 -algorithms,java I created ModelForms for Lecture and Subject .Then I created another SubjectNamesForm( which has no associated Model )to capture the many subject names a Lecture can have. When I edit a Lecture, I need to show the existing values from the Lecture in the template,so I used I can populate the LectureForm with info from existing instance using lecture=get_object_or_404(Lecture,id) lectureform=LectureForm(request.POST,instance=lecture) But how do I populate the subjectnamesform ? I tried the following ,but it shows only empty text field when subjectnamesform is rendered if request.method=='GET': subjectnamesform=SubjectNamesForm() subjectnamesform.subjects=[x.name for x in lecture.subjects.all()] return render_to_response('myapp/edit_lecture.html', {'lectureform':lectureform,'subjectnamesform':subjectnamesform}) Can someone help? thanks harry p.s: below is the listing of models. class Lecture(models.Model): speaker=models.ForeignKey(User) subjects=models.ManyToManyField(Subject) pub_date=models.DateField(default=date.today) class Subject(models.Model): name=models.CharField(unique=True,max_length=50) class LectureForm(forms.ModelForm): class Meta: model=Lecture exclude=('subjects',) class SubjectForm(forms.ModelForm): class Meta: model=Subject class SubjectNamesForm(forms.Form): subjects=models.CharField(max_length=400)# expects comma separated subject names like subject1,subject2 etc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to set default value as current time in TimeField
thanks ,that worked.. any idea about calculating the duration? I can do a - between two datetime.datetime objects to get a timedelta.. but that doesn't work with datetime.time objects harry On Feb 16, 12:37 pm, Masklinn wrote: > Just wrap the thing in a `lambda` and you should be good to go: > `default=(lambda:datetime.now().time)` -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to set default value as current time in TimeField
hi I am using a TimeField and want to set the default value as current time.I know the field normalizes to a datetime.time object.In a DateField ,I can put (default=datetime.date.today) and this will set the current day .Similarly I tried (default=datetime.now().time) for TimeField ..and can get a default time value when the page is loaded.But after waiting for a couple of minutes,I loaded the page again(without restarting the server) and the timevalue shown was the old one ,not current time. While using the django admin I can set the time using the javascript clock,but that is not an option when I use my own (beginner level)code..Can anyone tell me how I can get the current time as default value in the field? Also ,how do I get the duration between two datetime.time objects ?I tried to create two instances of these and can compare them using > or < ,but found that - operation is not supported.Any tips are most welcome thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
converting month string
hi In my view I am taking user input string for month( like 'jan','feb') and want to search the db for objects with those months as published time. def entry_archive_for_month(request,year,month): entryset=Entry.objects.filter(pub_time__year=year,pub_time__month=month) obviously this will cause ValueError since month='jan' but pub_time__month should be an integer Is there any way I can convert the month string into integer?Do I have to create a dictionary with all lowercase month strings and then call a function to return the matching integer?I would like to know if there is a better way. thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
error check for start ,end datetime values in view
hi I have an entry model and its modelform .The entry model has a start,end datetimes.I want to prevent the user from mistakenly entering an end datetime value which is before the start datetime.(ie, end=11feb2010 and start=12feb2010 is wrong).I tried to do the error check in an add_entry() view. I gave some print statements to find out values at each stage. I have given in my entry model definition default values for start,end datetimes as now (ie default=datetime.datetime.now) .Even if I give start time :2009-10-11 09:03:22 end time :2009-10-11 08:03:22(end_time is before start_time - intentionally) the print statements show that form.instance.start_time and form.instance.end_time are taken from the default values where end_time is >start_time This causes datecheck to return True and thus my error check doesn't work. However,the cleaned data shows the values which I entered while creating the entry. I can't understand why the form.instance is showing default values for the datetime fields whereas cleaned_data has the user input values.Can anyone tell me? def add_entry(request): print 'in add_entry()' errors={} if request.method=='POST': form=MyEntryForm(request.POST) print 'add_entry():got POST data' print 'form.instance.start_time=',form.instance.start_time print 'form.instance.end_time=',form.instance.end_time if form.is_valid() and date_check(form.instance.start_time,form.instance.end_time): cd=form.cleaned_data print 'add_entry():cleaned data;',cd print 'saving entry' form.save() return redirect('entry_archive_index') else: print 'add_entry():POST:invalid form' errors.update(form.errors) form=MyEntryForm() form=MyEntryForm() print 'add_entry()GET' return render_to_response('myapp/add_entry.html', {'entryform':form,'errors':errors}) def date_check(start,end): if start < end: return True else: return False Here is the output of print statements [11/Feb/2010 09:03:45] "GET /myapp/entries/addentry/ HTTP/1.1" 200 2181 in add_entry() add_entry():POST:form got from POST data form.instance.start_time= 2010-02-11 09:04:32.093058 form.instance.end_time= 2010-02-11 09:04:32.093152 add_entry():cleaned data; { 'start_time': datetime.datetime(2009, 10, 11, 9, 3, 22), 'end_time' : datetime.datetime(2009, 10, 11, 8, 3, 22)} saving entry [11/Feb/2010 09:04:32] "POST /myapp/entries/addentry/ HTTP/1.1" 302 0 So I rewrote the error check based on cleaned_data errors={} if form.is_valid(): cd=form.cleaned_data start_t=cd['start_time'] end_t=cd['end_time'] if not date_check(start_t,end_t): date_error={'datetime_error':'starttime should be before endtime !'} errors.update(date_error) return render_to_response('myapp/add_entry.html', {'entryform':form,'errors':errors}) print 'saving entry' form.save() return redirect('entry_archive_index') else: print 'add_entry():invalid form' errors.update(form.errors) form=MyEntryForm() return render_to_response('myapp/add_entry.html', {'entryform':form,'errors':errors}) This does the correct error checking ..Still I want to know if there is a better way of doing the error check on start and end dates..The above code looks like a jumble of if else statements..and I know that is not the best way of doing things thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
error check for start,end datetimes in model and form
hi I have an entry model and its modelform .The entry model has a start,end datetimes.I want to prevent the user from mistakenly entering an end datetime value which is before the start datetime.(ie, end=11feb2010 and start=12feb2010 is wrong).I tried to do the error check in an add_entry() view. I gave some print statements to find out values at each stage. I have given in my entry model definition default values for start,end datetimes as now (ie default=datetime.datetime.now) .Even if I give start time :2009-10-11 09:03:22 end time :2009-10-11 08:03:22(end_time is before start_time - intentionally) the print statements show that form.instance.start_time and form.instance.end_time are taken from the default values where end_time is >start_time This causes datecheck to return True and thus my error check doesn't work. However,the cleaned data shows the values which I entered while creating the entry. I can't understand why the form instance is showing default value.Can anyone tell me? def add_entry(request): print 'in add_entry()' errors={} now=datetime.datetime.now() if request.method=='POST': form=MyEntryForm(request.POST) print 'add_entry():got POST data' print 'form.instance.start_time=',form.instance.start_time print 'form.instance.end_time=',form.instance.end_time if form.is_valid() and date_check(form.instance.start_time,form.instance.end_time): cd=form.cleaned_data print 'add_entry():cleaned data;',cd print 'saving entry' form.save() return redirect('entry_archive_index') else: print 'add_entry():POST:invalid form' errors.update(form.errors) form=MyEntryForm() form=MyEntryForm() print 'add_entry()GET' return render_to_response('myapp/add_entry.html', {'now':now,'entryform':form,'errors':errors}) def date_check(start,end): if start < end: return True else: return False Here is the output of print statements [11/Feb/2010 09:03:45] "GET /myapp/entries/addentry/ HTTP/1.1" 200 2181 in add_entry() add_entry():POST:form got from POST data form.instance.start_time= 2010-02-11 09:04:32.093058 form.instance.end_time= 2010-02-11 09:04:32.093152 add_entry():cleaned data; { 'start_time': datetime.datetime(2009, 10, 11, 9, 3, 22), 'end_time' : datetime.datetime(2009, 10, 11, 8, 3, 22)} saving entry [11/Feb/2010 09:04:32] "POST /myapp/entries/addentry/ HTTP/1.1" 302 0 So I rewrote the error check based on cleaned_data errors={} if form.is_valid(): cd=form.cleaned_data print 'add_entry():cleaned data;',cd start_t=cd['start_time'] end_t=cd['end_time'] if not date_check(start_t,end_t): date_error={'datetime_error':'starttime should be before endtime !'} errors.update(date_error) return render_to_response('pomlogger/pomentry_add_entry.html', {'now':now,'entryform':form,'errors':errors}) print 'saving entry' form.save() return redirect('pomlog_entry_archive_index') else: print 'add_entry():POST:invalid form' errors.update(form.errors) form=PomEntryForm() return render_to_response('pomlogger/pomentry_add_entry.html', {'now':now,'entryform':form,'errors':errors}) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
slug is not autogenerated in edit page
I was trying out forms and created a class and its form class MyCategory(models.Model): name=models.CharField(max_length=10) description=models.TextField(help_text='a description about the category') slug=models.SlugField(unique=True,help_text='will be auto generated from name') class Meta: verbose_name_plural="MyCategories" def __unicode__(self): return self.name def get_absolute_url(self): return ('myapp_category_detail',(),{'slug':self.slug}) get_absolute_url=models.permalink(get_absolute_url) classMyCategoryForm(ModelForm): class Meta: model=MyCategory I set the slug to be auto generated in admin.py class MyCategoryAdmin(admin.ModelAdmin): prepopulated_fields= {'slug':['name']} ordering=['name'] After that I created an edit view for the class def edit_category(request,slug): cat=get_object_or_404(MyCategory,slug=slug) if request.method=='POST': form=MyCategoryForm(request.POST,instance=cat) if form.is_valid(): form.save() redirect('myapp_category_list') else: print 'edit_category::invalid form' form=MyCategoryForm(instance=cat) else: form=MyCategoryForm(instance=cat) return render_to_response('myapp/edit_category.html', {'categoryform':form}) In the edit_category.html I displayed the form as {{ categoryform.as_table }} When the template is rendered it shows the helptext which I provided in the model's slugfield.But unlike in the django admin 's edit page ,the slug is not auto generated when I type in a new name for the category. Similarly I tried an add category page.Here also the slug is not auto generated,even though the helptext says that it will be.I have enabled javascript for my browser.Do I have to write a javascript for each of these pages or can I use some script the admin uses? I am only getting familiar with the basics..so please bear with the newbish doubts thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to redirect to 'next'
hi In my login_view I am redirecting to an archive page as below def login_view(request): if request.method=='POST': username=request.POST['username'] password=request.POST['password'] user = authenticate(username=username, password=password) if user is not None and user.is_active: login(request, user) return redirect('myapp_archive_index')#default page else: return render_to_response('myapp/login.html') else: return render_to_response('myapp/login.html') In login template for I am using the hidden field 'next' ... I have given the LOGIN_URL as '/myapp/login/and in urlconf set this to the above login_view method . url(r'^','myapp.views.login_view',name='myapp_login'), Also I have many views to list the entries belonging to an year,month etc..All of them have @login_required . eg: @login_required def entry_archive_year(request,year,month): return render_to_response('myapp/archive_month.html',somedict) Now if I try to access /myapp/entries/1999/jan/ ,I will get the login page .The url on browser search field is /myapp/login/?next=/myapp/ entries/1999/jan/.If I login correctly ,I would like the page to go to /entries/1999/jan/ and not to the 'myapp_archive_index' page I provided in the login_view method.Is there a way to redirect to the value pointed to by this 'next'? thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
implementing login in application,gets ValueError
I was trying to create login in my application .As per what is given in djangobook I created the login view as follows def login_view(request): if request.method=='POST': print 'login_view()::POST' username=request.POST['username'] password=request.POST['password'] print 'login_view:from req got username=',username print 'login_view:from req got password=',password user = authenticate(username=username, password=password) if user is not None and user.is_active: print 'login_view:login success' login(request, user) return redirect('myapp_entry_archive_index') else: print 'login_view:GET method' print 'login_view:login failed' return render_to_response('myapp/login.html') I also created these urls, projects url.py (r'^myapp/',include('myapp.urls.login')), urls/login.py --- urlpatterns=patterns('', url(r'^','myapp.views.login_view',name='myapp_login'), ) Also a login page login.html -- This is the login page Username: Password: when I give a wrong username password combination ,I get this error ValueError,.views.login_view didn't return an HttpResponse object. Can someone help me correct this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: getting dictionary values on template
thanks Javier..will read the docs .. > why so harsh to a newbie? that link doesn't help the question, > {{mydata_dict.key}} won't help, since 'key' here is also a variable. > > the answer is: > > {% for key, value in mydata_dict.items %} > {{key}} = {{ value }} > {% endfor %} > > and is documented in a different part: > (http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#for) > which might not be too obvious to somebody that's new to python. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
getting dictionary values on template
hi I have a dictionary object passed to the template , from which I need to retrieve values mydata={} mydict['chemistry']=120 mydict['physics']=164 mydict['maths']=110 In my render_to_response I passed this object like return render_to_response("myapp/mydatapage.html", {'mydata_dict':mydata}) I need to show this data on the page as chemistry=120 physics=164 math=110 On the template html, I tried this {% for key in mydata_dict %} {{key}} ={{ mydata_dict[key] }} {% endfor %} This gives TemplateSyntaxError :Could not parse the remainder: '[key]' from 'mydata_dict[key]' I understand template doesn't allow [] operator..Can somebody tell me how I can get the value corresponding to the key? thanks harry How else -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
uniquely identifying an entry
hi (sorry about this newbie question..) I have designed an entry and a category as follows. The entry doesn't have a title.(The user is not expected to provide a title for it )It is uniquely identified by a combination of its published datetime and the name of the category it belongs to. class MyCategory(models.Model): name=models.CharField(max_length=10) description=models.TextField() slug=models.SlugField(unique=True) def __unicode__(self): return self.name class MyEntry(models.Model): posted_time=models.DateTimeField(default=datetime.now) category=models.ForeignKey(MyCategory) description=models.TextField() author=models.ForeignKey(User) def __unicode__(self): return "%s%s"%(self.category.name,self.posted_time) I would like to list all entries posted at different minutes in an hour. and also show the details of a single entry.I am not sure how I can do this. I am wondering if I can get details of an entry like /myapp/entries/2010/jan/01/10/35/splcat sothat I can get an entry belonging to 'splcat' posted at 10 hrs,35 minutes on 1st jan 2010. Is there some way I can do lookup on the hour,minute of posted_time? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
FieldError with get_object_or_404
hi I was trying out in django's python shell the get_object_or_404 method on a set of entries I created in the db.I created an entry with a DateTimeField called 'posted_time'.I used datetime.datetime.now as default value and it created Date:2010-02-01 Time:10:02:22 I also created many other such entries with different datetime values In the shell I tried this from django.shortcuts import get_object_or_404 as gtobj e1=gtobj(MyEntry,posted_time__year=2010,posted_time__month=2,posted_time__day=1) This is successful ,it gives this message MultipleObjectsReturned: get() returned more than one MyEntry -- it returned 4! However when I tried , e1=gtobj(MyEntry,posted_time__year=2010,posted_time__month=2,posted_time__day=1,posted_time__hour=10) I get this error, FieldError: Join on field 'posted_time' not permitted. Did you misspell 'hour' for the lookup type? Why is this happening?can someone help me figure this out?I tried various values for the hour and minute ..the same error happens for minute also. thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to generate slug from datetime and another model's field
hi I have an Entry class that has no title but is to be represented uniquely by a combination of its category and a datetime value.The Category has a name field.I have modelled these like class MyCategory(models.Model): name=models.CharField(max_length=10) description=models.TextField(help_text='a description about the category') slug=models.SlugField(unique=True,help_text='will be auto generated from name') class Meta: verbose_name_plural="MyCategories" def __unicode__(self): return self.name class MyEntry(models.Model): posted_time=models.DateTimeField(default=datetime.now) category=models.ForeignKey(MyCategory) description=models.TextField() slug=models.SlugField(unique=True,help_text='will be auto generated from category and date') class Meta: verbose_name_plural="MyEntries" def __unicode__(self): return self.slug In admin module ,I have created 2 admins class MyEntryAdmin(admin.ModelAdmin): prepopulated_fields= {'slug':['category','posted_time']} class MyCategoryAdmin(admin.ModelAdmin): prepopulated_fields= {'slug':['name']} ordering=['name'] admin.site.register(MyEntry,MyEntryAdmin) admin.site.register(MyCategory,MyCategoryAdmin) I think there is something wrong with the way I am creating the slug for MyEntry..It doesn't get created at all..I couldn't figure out how to do this.I would like to have a slug like 'programming-1010jan21-01-30-56' or similar .Can someone tell me how I can do this. Without a unique slug to represent an entry ,the admin interface lists all entries using the same string (MyEntry Object or something like that).. thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: logic of forloop.revcounter and revcounter0
thanks Bill for the detailed answer..it really helped me to understand the logic harry Bill Freeman wrote: > Looking at the code in django/template/defaulttags.py, where len_values > is the number of itterations in the loop: > > counter0 runs from 0 through len_values-1 > counter runs from 1 through len_values > revcounter runs from len_values down to 1 (essentially it is > len_values - counter0) > revcounter0 runs from len_values-1 down to 0 (len_values-counter) > > Since you're printing 'and' after you print tag.name, you want to do > it in the penultimate > iteration. At this point revcounter will be 2. That is, counting > this iteration, there are > 2 iterations left in the loop. revcounter9 will be 1 at this point, > because there is one > iteration after the current one. > > So you can check {% ifequal forloop.revcounter 2 %} or you can check > {% ifequal forloop.revcounter0 1 %}. > > By the way, you don't need the forloop last check, as either of the above > automatically don't happen on the last iteration. > > An alternative would be to (conditionally) print the "and" before > tag.name in the loop, > where you only have to use last: > > ... > {% for tag in taglist %%}{% if forloop.last %} and{% endif %} {{ > tag.name }}{% endfor %} > > And note that {% if forloop.last %} is roughly equivalent to {% > ifequal forloop.revcounter0 0 %} or > {% ifequal forloop.revcounter 1 %}. > > To get a better handle on what has which value when, you could sprinkle > some {{ forloop.revcounter }} and {{ forloop.revcounter0 }} instances in your > loop. > > Bill > > On Tue, Feb 2, 2010 at 4:30 AM, harryos wrote: > > hi > > While trying out lessons on templates.I tried using the variables in > > 'for' to print the names of 2 tags in a list called taglist.(template > > code is given at the bottom) > > I could n't understand why ifequal forloop.revcounter0 1 is used > > instead of revcounter.. > > I tried to follow the logic using revcounter variable, > > > > 1st iteration of for: > > print tagname of first tag > > current iteration is not the last > > check if 1 iteration is left ,revcounter should return 1 since 1 > > more iter is left,so should print the word 'and' > > 2nd iteration: > > print tagname of second tag > > forloop.last is true,nothing printed > > forloop ends > > > > According to above logic I should be getting the result as > > firsttag and secondtag > > Still ,I got the correct result only when i used ifequal > > forloop.revcounter0 1 > > > > Can someone tell me how I got the logic wrong..I am quite confused > > thanks > > harry > > > > {% load tagging_tags %} > > {% tags_for_object object as taglist %} > > > > {% if taglist.count %} > > {{ taglist.count}} Tags for this link are : > > {% for tag in taglist %} > > {{tag.name}} > > {% if forloop.last %} {% else %} > > {% ifequal forloop.revcounter 1 %} and {% else %},{% endifequal %} > > {% endif %} > > {% endfor %} > > {% else %} > > No tags for this link > > {% endif %} > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > > http://groups.google.com/group/django-users?hl=en. > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
logic of forloop.revcounter and revcounter0
hi While trying out lessons on templates.I tried using the variables in 'for' to print the names of 2 tags in a list called taglist.(template code is given at the bottom) I could n't understand why ifequal forloop.revcounter0 1 is used instead of revcounter.. I tried to follow the logic using revcounter variable, 1st iteration of for: print tagname of first tag current iteration is not the last check if 1 iteration is left ,revcounter should return 1 since 1 more iter is left,soshould print the word 'and' 2nd iteration: print tagname of second tag forloop.last is true,nothing printed forloop ends According to above logic I should be getting the result as firsttag and secondtag Still ,I got the correct result only when i used ifequal forloop.revcounter0 1 Can someone tell me how I got the logic wrong..I am quite confused thanks harry {% load tagging_tags %} {% tags_for_object object as taglist %} {% if taglist.count %} {{ taglist.count}} Tags for this link are : {% for tag in taglist %} {{tag.name}} {% if forloop.last %} {% else %} {% ifequal forloop.revcounter 1 %} and {% else %},{% endifequal %} {% endif %} {% endfor %} {% else %} No tags for this link {% endif %} -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: doubt about permalink and name in urlpatterns
> So you can use them with the {% url %} tag in templates, as shown later on. thanks a lot harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
doubt about permalink and name in urlpatterns
In Bennet's book ,chapter4, decoupling the urls (page 74 in my ebook) ,the name 'coltrane_entry_detail' is added to the urlpattern for an entry and the get_absolute_url() method in class Entry makes use of that name ,and permalink causes the method to output correct url. But I can't understand why the names are given to the other url patterns .For example the names 'coltrane_entry_archive_day' ,'coltrane_entry_archive_month' etc are never used in any method in class Entry.Even if I remove it from the urlpattern the entries will be listed properly and get_absolute_url in template will point to the correct url.Can anyone explain why these names are there? thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
viewsite button takes me to example.com
hi I was trying out the weblog app in bennet's book.I created some categories and entries and can list them properly using http://127.0.0.1:8000/myblog/ and http://127.0.0.1:8000/myblog/categories The admin interface also lists the categories properly when I try http://127.0.0.1:8000/admin/myblog/category/ But when I go to the Change Category page for a category and try the view site button ,it takes me to http://example.com/categories/someslug/ instead of my localhost.I couldn't figure out why this is happening.Can someone help? thanks harry p.s: I have set the get_absolute_url to return "/categories/%s/"%self.slug in Category and "/harryblog/%s/%s/"% (self.pub_date.strftime("%Y/%b/%d").lower () ,self.slug) in Entry. In the project urls file I have set these patterns: (r'^admin/', include(admin.site.urls)), (r'^harryblog/categories/',include('myblog.urls.categories')), (r'^harryblog/',include('myblog.urls.entries')), http://example.com/categories/meditation/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re:login failure
On Jan 24, 10:45 pm, Daniel Roseman wrote: > You put them in your project's settings.py (which, through some magic, > is imported via django.conf). You should not be editing any of the > code inside Django itself, unless you know what you're doing. Thanks for the reply..I added the login data to my project settings and tried to post a link to delicious site using my yahoo id as below.I can manually login at yahoo page using the same login data .But when I try to do the following I get an raise PyDeliciousUnauthorized, "Check credentials." error >>> from pydelicious import DeliciousAPI; from getpass import getpass >>> pwd = getpass('Pwd:') Pwd:#i entered my password here >>> a = DeliciousAPI('myusername', pwd) >>> a.posts_add("http://my.com/";, "title", tags="my tags") can anyone help me find out why this is happening? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
where to put the username password data
hi I was going thru bennet's practical django book..In the weblog app it mentions that the DELICIOUS_USER ,DELICIOUS_PASSWORD values should be set in settings file.The book mentions an import like from django.conf import settings When I looked thru the directory in django/conf I could not find a settings.py file.There is a global_settings.py file.In which file should I put these values? thanks harry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.