from django.contrib import admin
from .models import Profile
from import_export.admin import ImportExportModelAdmin
# Register your models here.
class ProfileAdmin(ImportExportModelAdmin, admin.ModelAdmin):
pass
admin.site.register(Profile)
class ContactU(forms.Form):
first_name = forms.CharField(max_length = 50)
last_name = forms.CharField(max_length = 50)
email_address = forms.EmailField(max_length = 150)
message = forms.CharField(widget = forms.Textarea, max_length = 2000)
class Meta:
model = User
fields = ('first_name','last_name','email_address','message')
جزء من كود HTML:
<formmethod="POST"enctype="multipart/form-data">
{% csrf_token %}
<divclass="row"><divclass="col-md-4 form-group"><inputtype="text"name="first_name"class="form-control"id="first_name"placeholder="first_name"data-rule="minlen:4"data-msg="Please enter at least 4 chars">
{{form.first_name}}
<divclass="validate"></div></div><divclass="col-md-4 form-group mt-3 mt-md-0"><inputtype="tel"class="form-control"name="email_address"id="email_address"placeholder="email_address"data-rule="minlen:4"data-msg="Please enter at least 2 chars">
{{form.email_address}}
<divclass="validate"></div></div>
السؤال
Zeina Almakdisi
مرحبا لدي فورم "تواصل معنا" لايظهر أي رسالة خطأ لكن لايتم ارسال البيانات الى قاعدة البيانات
Settings.py
INSTALLED_APPS = [ 'import_export', ... ] DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME':'medical', 'USER': 'root', 'PASSWORD':'', 'HOST': '127.0.0.1', 'PORT': '3306', } }
admin.py
from django.contrib import admin from .models import Profile from import_export.admin import ImportExportModelAdmin # Register your models here. class ProfileAdmin(ImportExportModelAdmin, admin.ModelAdmin): pass admin.site.register(Profile)
views.py
def contact_U(request): if request.method == 'POST': form = ContactU(request.POST) if form.is_valid(): subject = "Website Inquiry" body = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'email': form.cleaned_data['email_address'], 'message':form.cleaned_data['message'], } message = "\n".join(body.values()) try: send_mail(subject, message, 'admin@example.com', ['admin@example.com']) except BadHeaderError: return HttpResponse('Invalid header found.') # return redirect ("accounts:Thanks") form = ContactU() return render(request, 'user/contact_U.html', { 'contact_U' : contact_U, })
forms.py
class ContactU(forms.Form): first_name = forms.CharField(max_length = 50) last_name = forms.CharField(max_length = 50) email_address = forms.EmailField(max_length = 150) message = forms.CharField(widget = forms.Textarea, max_length = 2000) class Meta: model = User fields = ('first_name','last_name','email_address','message')
جزء من كود HTML:
6 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.