url = f"https://query.yahooapis.com/v1/public/yql?q="\
+ f"select%20*%20from%20weather.forecast%20where%20w" \
+ f"oeid%20in%20(select%20woeid%20from%20geo.places("\
+ f"1)%20where%20text%3D%22{city}%22)%20and%20u%3D%2" \
+ f"7c%27&format=json&env=store%3A%2F%2Fdatatables.o" \
+ f"rg%2Falltableswithkeys"
def auth(request):
email = request.POST['email']
password = request.POST['password']
get_user = get_object_or_404(User, email=email)
user = authenticate(username=get_user.username, password=password)
if user is not None and user.is_active:
login(request, user)
return HttpResponseRedirect(reverse('shop:index'))
is_rule1 = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
if request.method == 'POST':
form = AddDesc(request.POST)
form.is_valid()
email = form.cleaned_data['email']
username = form.cleaned_data['username']
last = form.cleaned_data['last_name']
if not email == '':
user.email = email
if not username == '':
user.username = username
if not last == '':
user.last_name = last
user.save()
from django.contrib.auth.models import User
def password_reset(request):
u = User.objects.get(username='john')
u.set_password('new password')
u.save()
#return формируете интересующую форму
urlpatterns = [
url(r'^password_reset/$', views.password_reset, name='password_reset'),
]
from django.conf.urls import url, include
from django.contrib.auth import views as auth_views
urlpatterns = [
url(r'^accounts/login/$', auth_views.login, {'template_name': 'myapp/login.html'}),
]
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
MEDIA_URL = '/templates/'
{#ЭТОТ ШАБЛОН предполагает, что у вас есть шаблон base.html, который определяет блок content#}
{% extends "myapp/base.html" %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{# Assumes you setup the password_reset view in your URLconf #}
{% endblock %}
from django.contrib.auth.models import Permission, User
from django.contrib import auth
def index(request):
product_all = Product.objects.all()[:12]
# сессия пользователя
user = request.user
set = {
'product_all' : product_all,
'user' : user
}
try:
return render(request, 'shop/index.html', set)
except(KeyError, Product.DoesNotExist):
return render(request, 'shop/404.html')
{% block auth %}
<div class="log_in">
{% if user.is_anonymous %}
<form action="{% url 'shop:auth' %}" method="post">
{% csrf_token %}
<input type="text" name="login" placeholder="e-mail" />
<input type="password" name="password" placeholder="password" />
<input type="submit" value="Submit" />
</form>
{% else %}
<a href="{% url 'auth:profile' %}">Profile</a>
{% endif %}
</div>
{% endblock %}
url(r'auth/$', views.auth, name='auth'),