Re: Unable to Save form to mysql - How to save form field values to mysql database and get the value from database

2018-07-02 Thread Andréas Kühne
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 :

> 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.py*
>
> from django.http import HttpResponseRedirect
> from django.views import View
> from django.shortcuts import render
>
> from .forms import NameForm
>
> def get_name(request):
> # if this is a POST request we need to process the form data
> if 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 form
> else:
> form = NameForm()
>
> return render(request, 'portal/index.html', {'form': form})
>
>
> djangoproject/urls.py
>
> from django.contrib import admin
> from django.urls import path, include
> #from django.conf.urls import url, include
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('portal/', include('portal.urls')),
> #url(r'^portal/', include('portal.urls'))
> ]
>
>
> *forms.py*
>
> from django import forms
>
> # class NameForm(forms.Form):
> # your_name = forms.CharField(label='Your name', max_length=100)
>
>
> *urls.py*
>
> from django.conf.urls import url
> from . import views
>
> urlpatterns = [
> 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  check_errors..wrappe
>  at 0x0355E4F8>
> Traceback (most recent call last):
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\
> utils\autoreload.py"
>  line 225, in wrapper
> fn(*args, **kwargs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\comm
> nds\runserver.py", line 120, in inner_run
> self.check(display_num_errors=True)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\base
> py", line 364, in check
> include_deployment_checks=include_deployment_checks,
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> management\base
> py", line 351, in _run_checks
> return checks.run_checks(**kwargs)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\registry
> py", line 73, in run_checks
> new_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_config
> return check_resolver(resolver)
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\
> checks\urls.py"
>  line 23, in check_resolver
> return check_method()
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\
> resolvers.py",
> ine 399, in check
> for 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_patterns
> patterns = 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_module
> return import_module(self.urlconf_name)
>   File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126,
> in impo
> t_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 994, in _gcd_import
>   File "", line 971, in _find_and_load
>   File "", line 955, in
> _find_and_load_unlocked
>   File "", line 665, in _load_unlocked
>   File "", line 678, in exec_module
>   File "", line 219, in
> _call_with_frames_removed
>   File "c:\TransportPortal\djangoproject\djangoproject\urls.py", line 22,
> in  dule>
> path('portal/', include('portal.urls')),
>   File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\conf.py",
> line
> 4, in include
> urlconf_module = import_module(urlconf_module)
>   File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126,
> in impo
> t_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 994, in _gcd_import
>   File "", line 971, in _find_and_load
>   File "", line 955, in
> _find_and_load_unlocked
>   File "", line 665, in _load_unlocked
>   File "", 

Unable to Save form to mysql - How to save form field values to mysql database and get the value from database

2018-07-02 Thread Tamilvanan Anbalagan
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.py*

from django.http import HttpResponseRedirect
from django.views import View
from django.shortcuts import render

from .forms import NameForm

def get_name(request):
# if this is a POST request we need to process the form data
if 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 form
else:
form = NameForm()

return render(request, 'portal/index.html', {'form': form})


djangoproject/urls.py

from django.contrib import admin
from django.urls import path, include
#from django.conf.urls import url, include

urlpatterns = [
path('admin/', admin.site.urls),
path('portal/', include('portal.urls')),
#url(r'^portal/', include('portal.urls'))
]


*forms.py*

from django import forms

# class NameForm(forms.Form):
# your_name = forms.CharField(label='Your name', max_length=100)


*urls.py*

from django.conf.urls import url
from . import views

urlpatterns = [
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 .wrappe
 at 0x0355E4F8>
Traceback (most recent call last):
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\utils\autoreload.py"
 line 225, in wrapper
fn(*args, **kwargs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\comm
nds\runserver.py", line 120, in inner_run
self.check(display_num_errors=True)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\base
py", line 364, in check
include_deployment_checks=include_deployment_checks,
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\management\base
py", line 351, in _run_checks
return checks.run_checks(**kwargs)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\registry
py", line 73, in run_checks
new_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_config
return check_resolver(resolver)
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\core\checks\urls.py"
 line 23, in check_resolver
return check_method()
  File 
"C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\resolvers.py",
ine 399, in check
for 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_patterns
patterns = 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_module
return import_module(self.urlconf_name)
  File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in 
impo
t_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File "c:\TransportPortal\djangoproject\djangoproject\urls.py", line 22, 
in 
path('portal/', include('portal.urls')),
  File "C:\Users\nb97441\Envs\py1\lib\site-packages\django\urls\conf.py", 
line
4, in include
urlconf_module = import_module(urlconf_module)
  File "C:\Users\nb97441\Envs\py1\lib\importlib\__init__.py", line 126, in 
impo
t_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in 
_call_with_frames_removed
  File "c:\TransportPortal\djangoproject\portal\urls.py", line 6, in 

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