I was making a django app which would be able to send and receive emails. For the django app I was writing the code for views.py After I ran the file, I got stuck with this error. This is the views.py from my django app
from django.shortcuts import render
from django.contrib import messages
from django.core.mail import send_mail
#from demoapp.form import ContactForm
# Create your views here.
def index(request):
return render(request,'index.html',{'page':'home'})
def contact(request):
try:
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
send_mail(form.cleaned_data)
messages.success(request,'Your message is successfully submitted')
else:
form = ContactForm()
except:
messages.error(request,'contact.html',{'page':'contact','form':form})
def clear(request):
form = ContactForm()
messages.error(request,'Fields Cleared')
return render(request,'contact.html',{'page':'contact','form':form})
Urls.py This urls.py is from the django project. I havent created any urls.py for my app.
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from demoapp.views import index,about,contact,clear
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$' , index , name=index),
url(r'^about/$' , about , name=about),
url(r'^contact/$' , contact , name=contact),
url(r'^clear/$' , clear , name=clear),
]
After I run python3 manage.py runserver I get the following error
Watching for file changes with StatReloader
Performing system checks...
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 399, in check
messages.extend(check_resolver(pattern))
File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 325, in check
warnings = self._check_pattern_name()
File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 333, in _check_pattern_name
if self.pattern.name is not None and ":" in self.pattern.name:
TypeError: argument of type 'function' is not iterable
urls.py.name, somewhere in your code?clearview is also somewhat "strange". One typically does not do that through a view. Typically this is done in the HTML/JavaScript.contactnever returns a response.