in settings.py
in TEMPLATE_DIRS put all your templates folders where django go to find them
in MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
in INSTALLED_APPS = (
'django.contrib.auth', #important to login and logout
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'YourProject.YourApp',
)
'django.contrib.auth', #important to login and logout
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'YourProject.YourApp',
)
and create this
LOGIN_URL = '/url/to/login/'
LOGOUT_URL = '/url/to/logout/'
LOGIN_REDIRECT_URL = '/url/to/your/view'
LOGIN_URL = '/url/to/login/'
LOGOUT_URL = '/url/to/logout/'
LOGIN_REDIRECT_URL = '/url/to/your/view'
in your general urls.py
from django.contrib.auth.views import login, logout_then_login
from django.conf.urls.defaults import patterns, url, include
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^YourApp/', include('YourProject.YourApp.urls')),
(r'^login/$', login, {'template_name': 'login.djhtml'}),
(r'^logout/$', logout_then_login),
# For admin
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
in YourApp/urls.py
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('YourProject.YourApp.views',
url(r'^$', 'YourViewName'),
)
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('YourProject.YourApp.views',
url(r'^$', 'YourViewName'),
)
need a base.djhtml in YourTemplateFolder
in YourTemplateFolder/login.djhtml
{% extends "base.djhtml" %}
{% block cuerpo %}
{% if form.errors %}
<p>Su nombre de usuario y contraseña no coinciden. Por favor intente nuevamente.</p>
{% endif %}
<form method="post" action="">
{% csrf_token %}
<label>Nombre de Usuario</label><input id="id_username" type="text" name="username" maxlength="30" /><br />
<label>Clave de Usuario</label><input type="password" name="password" id="id_password" /><br />
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
in YourTemplateFolder/login.djhtml
{% extends "base.djhtml" %}
{% block cuerpo %}
{% if form.errors %}
<p>Su nombre de usuario y contraseña no coinciden. Por favor intente nuevamente.</p>
{% endif %}
<form method="post" action="">
{% csrf_token %}
<label>Nombre de Usuario</label><input id="id_username" type="text" name="username" maxlength="30" /><br />
<label>Clave de Usuario</label><input type="password" name="password" id="id_password" /><br />
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
in your YourApp/views.py
from django.contrib.auth.decorators import login_required
from django.template.context import RequestContext
@login_required
def yourViewName(Request):
return render_to_response('yourTemplate', {'YourDict': yourDict},
context_instance=RequestContext(Request))
2013/9/27 Joachim Wuttke <j1wuttke@gmail.com>
With user login to the user views.
I would like to build my application by incrementally modifying a working small application
that is just a little more complete than the poll application from the basic tutorial.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
--
Rafael E. Ferrero
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment