Hello engineer KenWhitesell
I hope that you are well
I have a problem that I could not find a solution to, and I tried all methods to find a solution.
Notice the codes written below
The login page works, as I enter the username and password, then when I press the register button, nothing happens, it remains in the same place and the page did not change until it did not appear that I was registered.
Note that when I register as an admin, it appears in the top bar that I am registered
The problem is this doesn’t work for me…
{{ form.username|as_crispy_field }}
or i don’t understand
may you help me?
views.py
def user_login(request):
if request.method =='POST':
form = Login_Form()
username = request.POST['username']
password = request.POST['password']
user = authenticate (request, username=username, password=password)
if user is not NONE:
login(request, user)
return redirect ('accounts:doctors_list')
else:
form = Login_Form()
return render(request, 'user/login.html', {
'form' : form
})```
urls.py for app
from django.urls import path
from . import views
app_name = ‘accounts’
urlpatterns = [
# path(‘app/’, views.app, name=‘app’),
path(‘doctors/’, views.doctors_list, name=‘doctors_list’),
path(‘login/’, views.user_login, name=‘login’),
path(‘signup/’, views.signup, name=‘signup’),
path(‘myprofile/’, views.myprofile, name=‘myprofile’),
path(‘update_profile/’, views.update_profile, name=‘update_profile’),
path('<slug:slug>/', views.doctors_detail, name='doctors_detail'),
]
user_signup
forms.py
class Login_Form(forms.ModelForm):
username = forms.CharField(max_length=50, label=‘الاسم’)
password = forms.CharField(max_length=50, label=‘كلمة المرور’, widget=forms.PasswordInput())
class Meta:
model = User
fields = ['username', 'password']
models.py
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext as _
from django.db.models.signals import post_save
from django.utils.text import slugify
Create your models here.
TYPE_OF_PERSON = (
(‘M’,“Male”),
(‘F’,“Female”),
)
class Profile(models.Model):
DOCTOR_IN = {
('جلدية', "جلدية"),
('أسنان', "أسنان"),
('عظام', "عظام"),
('جراحة', "جراحة"),
('أطفال', "أطفال"),
('أعصاب', "أعصاب"),
}
user = models.OneToOneField(User, verbose_name=_("user"), on_delete=models.CASCADE)
name = models.CharField(_("الإسم :"), max_length=50, blank=True, null=True)
surname = models.CharField(_("اللقب :"), max_length=50, blank=True, null=True)
who_i = models.TextField(_("من أنا :"), max_length=500, blank=True, null=True)
price = models.IntegerField(_("سعر الكشف :"), blank=True, null=True)
image = models.ImageField(_("الصورة الشخصية"),upload_to='profile/', height_field=None, width_field=None, max_length=100,blank=True, null=True)
slug = models.SlugField(_("slug"), blank=True, null=True)
subtitle = models.CharField(_("نبذة عنك :"), max_length=50, blank=True, null=True)
address = models.CharField(_("المحافظة :"), max_length=50, blank=True, null=True)
address_detail = models.CharField(_("العنوان بالتفصيل :"), max_length=50, blank=True, null=True)
number_phone = models.CharField(_("الهاتف :"), max_length=50, blank=True, null=True)
working_hours = models.CharField(_("عدد ساعات العمل :"), max_length=50, blank=True, null=True)
Waiting_time = models.IntegerField(_("مدة الانتظار :"), blank=True, null=True)
doctor = models.CharField(_("دكتور؟ :"), choices = DOCTOR_IN, max_length=50, blank=True, null=True)
Specialist_doctor = models.CharField(_("متخصص في ؟ :"), max_length=100, blank=True, null=True)
facebook = models.CharField(_("حساب الفيس بوك :"), max_length=150, blank=True, null=True)
twitter = models.CharField(_("حساب تويتر :"), max_length=150, blank=True, null=True)
google =models.CharField(_("حساب قوقل :"), max_length=150, blank=True, null=True)
join_new = models.DateTimeField(auto_now_add=True,blank=True, null=True)
type_of_person = models.CharField(_("النوع :"), max_length=50, blank=True, null=True, choices = TYPE_OF_PERSON)
login.html
{% extends 'base.html' %}
{% load static %}
{% load crispy_forms_tags %}
{% comment %} {% load bootstrap4 %} {% endcomment %}
{% block body %}
<form class="container mt-5 p-5">
<div dir="rtl">
<div class="container mt-5 p-5">
<div class="signup">
<div class="col-md-9" >
<form method="POST" enctype="multipart/form-data">
<h4 class="auth-header">تسجيل الدخول</h4>
{% csrf_token %}
<div class="form-group">
{{ form.username|as_crispy_field }}
</div>
<div class="form-group">
{{ form.password|as_crispy_field }}
</div>
<div class="buttons-w "><button type="submit" class="btn btn-success ml-5">تسجيل</button>
</div>
</form>
</div>
</div>
</div>
</div>
setting
Application definition
INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘accounts’,
# ‘crispy_forms’,
# "crispy_bootstrap4",
"crispy_forms",
"crispy_bootstrap4",
]
CRISPY_ALLOWED_TEMPLATE_PACKS = “bootstrap4”
CRISPY_TEMPLATE_PACK = “bootstrap4”
TEMPLATES = [
{
‘BACKEND’: ‘django.template.backends.django.DjangoTemplates’,
# ‘DIRS’: [os.path.join(BASE_DIR, ‘templates’)],
‘DIRS’: [‘templates’],
‘APP_DIRS’: True,
‘OPTIONS’: {
‘context_processors’: [
‘django.template.context_processors.debug’,
‘django.template.context_processors.request’,
‘django.contrib.auth.context_processors.auth’,
‘django.contrib.messages.context_processors.messages’,
],
},
},
]
Static files (CSS, JavaScript, Images)
STATIC_URL = ‘/static/’
STATICFILES_DIRS = [
BASE_DIR / “static”,
“/var/www/static/”,
]
MEDIA_URL = ‘/media/’
MEDIA_ROOT = os.path.join(BASE_DIR, “media”)
STATICFILES_DIRS = [os.path.join(BASE_DIR, “static”)]
Default primary key field type
DEFAULT_AUTO_FIELD = ‘django.db.models.BigAutoField’
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
BASE_DIR = Path(file).resolve().parent.parent
LOGIN_URL = ‘accounts:login’