In your views file, you don't have any index method - that's what the error is saying. So you need to solve the url mapping for your index method.
-- Regards,
Andréas
2018-07-02 5:55 GMT+02:00 Tamilvanan Anbalagan <tamilanbalagan@gmail.com>:
Hi Team,--I am very new to django framework, iI am trying to using simple forms to save into mysql database. also any samples pls send it to me, which will help to understand the connectivity.see my sample code:views.pyfrom django.http import HttpResponseRedirectfrom django.views import Viewfrom django.shortcuts import renderfrom .forms import NameFormdef get_name(request):# if this is a POST request we need to process the form dataif request.method == 'POST':# create a form instance and populate it with data from the request:form = NameForm(request.POST)# check whether it's valid:if form.is_valid():# process the data in form.cleaned_data as required# ...# redirect to a new URL:return HttpResponseRedirect('/thanks/' )# if a GET (or any other method) we'll create a blank formelse:form = NameForm()return render(request, 'portal/index.html', {'form': form})djangoproject/urls.pyfrom django.contrib import adminfrom django.urls import path, include#from django.conf.urls import url, includeurlpatterns = [path('admin/', admin.site.urls),path('portal/', include('portal.urls')),#url(r'^portal/', include('portal.urls'))]forms.pyfrom django import forms# class NameForm(forms.Form):# your_name = forms.CharField(label='Your name', max_length=100)urls.pyfrom django.conf.urls import urlfrom . import viewsurlpatterns = [url(r'^$', views.index, name='index')]Error message:(py1) c:\TransportPortal\djangoproject>python manage.py runserver Performing system checks...Unhandled exception in thread started by <function check_errors.<locals>.wrappeat 0x0355E4F8>Traceback (most recent call last):File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\ utils\autoreload.py" line 225, in wrapperfn(*args, **kwargs)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\ management\comm nds\runserver.py", line 120, in inner_runself.check(display_num_errors=True) File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\ management\base py", line 364, in checkinclude_deployment_checks=include_deployment_checks, File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\ management\base py", line 351, in _run_checksreturn checks.run_checks(**kwargs)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\ checks\registry py", line 73, in run_checksnew_errors = check(app_configs=app_configs)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\ checks\urls.py" line 13, in check_url_configreturn check_resolver(resolver)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\ checks\urls.py" line 23, in check_resolverreturn check_method()File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\ resolvers.py", ine 399, in checkfor pattern in self.url_patterns:File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\ utils\functional.py" line 36, in __get__res = instance.__dict__[self.name] = self.func(instance)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\ resolvers.py", ine 540, in url_patternspatterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\ utils\functional.py" line 36, in __get__res = instance.__dict__[self.name] = self.func(instance)File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\ resolvers.py", ine 533, in urlconf_modulereturn import_module(self.urlconf_name) File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in impo t_modulereturn _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_importFile "<frozen importlib._bootstrap>", line 971, in _find_and_loadFile "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 665, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "c:\TransportPortal\djangoproject\djangoproject\ urls.py", line 22, in <m dule>path('portal/', include('portal.urls')),File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\ conf.py", line 4, in includeurlconf_module = import_module(urlconf_module)File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in impo t_modulereturn _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 994, in _gcd_importFile "<frozen importlib._bootstrap>", line 971, in _find_and_loadFile "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 665, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "c:\TransportPortal\djangoproject\portal\urls.py", line 6, in <module> url(r'^$', views.index, name='index')AttributeError: module 'portal.views' has no attribute 'index'(py1) c:\TransportPortal\djangoproject>
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c664666e- .f5c1-422c-bde9-e54636e05a06% 40googlegroups.com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCdjO9K2UmbxYmqbK6jWhyw4s%3DW_7y9_5i69aQ70PAUUdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment