Possible Duplicate:
Putting a django login form on every page
how can I add a log-in in my main_page in django? let us say that in my main_page i just want to have a log-in. for example, in my http://www.example.com, i have a log-in division for any user who visit the site.
here is my urls.py
urlpatterns = patterns('',
(r'^$', main_page),
(r'^product/$', product_save),
(r'^reserve/$', reserve_page),
(r'^product/select/$', product_select),
(r'^book/$', book_save),
(r'^api/', include('bookproj.api.urls')),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': os.path.join(settings.BASE_DIR, 'media'),
'show_indexes': True}),
(r'^login/$', 'django.contrib.auth.views.login'),)
my views.py :
def main_page(request):
product = Product.objects.all()
template = get_template('main_page.html')
variables = RequestContext(request, { 'product': product})
return render_to_response(
'main_page.html', variables
)
in logging-in i just type to www.example.com/login , this line direct us to log-in method :
(r'^login/$', 'django.contrib.auth.views.login')
but its direct us to another page to call the login.html. how can i do it that in main_page.html have already a log-in and I cannot go anymore to www.example.com/login to log-in?
does anyone have an idea about my question? can i add another views or modify my main_page view?
thanks…
had this issue before , i think code here does exactly what you need
http://www.nerdydork.com/django-login-form-on-every-page.html
that explains how to put login on every page( by passing it to the base template )
if you want it only in the main page .. pass it to the main page instead of the base template
it’s a tutorial that explain how to build such a tasks . hope it helps