tags:

views:

47

answers:

2

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.

  1. Model
  2. View Function
  3. 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
thank you for this idea ...
mohammadmonther
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
its good tools im used it thank you very much
mohammadmonther