N
N
Neznai_ka2018-05-02 20:31:17
Django
Neznai_ka, 2018-05-02 20:31:17

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')),

urls.py from contact directory
rom django.conf.urls import patterns, include, url
 
urlpatterns = patterns[
           url(r'^$', 'views.contact', name='contact'),
]

views.py
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

2 answer(s)
T
tema_sun, 2018-05-02
@tema_sun

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.

R
Rostislav Grigoriev, 2018-05-02
@crazyzubr

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 question

Ask a Question

731 491 924 answers to any question