Answer the question
In order to leave comments, you need to log in
There is an error somewhere in the path, but where?
urls.py (main)
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# ...
# будем подключать urls.py приложения contact
url(r'^contact/', include('contact.urls')),
rom django.conf.urls import patterns, include, url
urlpatterns = patterns[
url(r'^$', 'views.contact', name='contact'),
]
from django.shortcuts import render
from django.http import HttpResponse
def contact(request):
errors = []
form = {}
if request.POST:
form['name'] = request.POST.get('name')
form['email'] = request.POST.get('email')
form['message'] = request.POST.get('message')
if not form['name']:
errors.append('Заполните имя')
if '@' not in form['email']:
errors.append('Введите корректный e-mail')
if not form['message']:
errors.append('Введите сообщение')
if not errors:
# ... сохранение данных в базу
return HttpResponse('Спасибо за ваше сообщение!')
return render(request, 'contact.html', {'errors': errors, 'form':form})
Answer the question
In order to leave comments, you need to log in
The error is here:
urlpatterns = patterns [
url(r'^$', 'views.contact', name='contact'),
patterns is a function where the first argument is a prefix. But in general, it was depriked a long time ago and you can just use the list.
Import views and remove quotes from 'views.contact'
from contact import views
#...
url(r'^$', views.contact, name='contact'),
# ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question