Hello >>>> i want make page counter to display the number of visitors who have viewed a page on my site
+1
A:
A "page counter" is what? A persistent piece of data which gets updated by view functions and displayed by a template.
As you are no doubt already aware, all Django things have the following parts.
- Model
- View Function
- Template
Model
If you want to keep the page counter in the database, you need a Django model.
class PageCounter( Model ):
You need to put a row into this model. Usually a "fixture" will help do this, since it's one row and you only put it in once when doing a syncdb.
View Function
Then you need to fetch and update the page counter in your view function.
pageCounter= PageCounter.objects.all()[0]
pageCounter.count += 1
pageCounter.save()
Template
Now you need to provide the value to your templates so it can be displayed.
S.Lott
2010-08-04 22:22:19
thank you for this idea ...
mohammadmonther
2010-08-06 13:33:48
A:
a page counter.. there is a django app for that problem. http://github.com/thornomad/django-hitcount.. easy to used and it is reusable..
Ralph
2010-08-05 08:03:10