im making a simple email subscription project.i have a html file which is having email text field.And now i want to get the entered email value from the html page and store it in mysql database.I dont know how to move on.i googled and saw everywhere but iam not able to understand properly.i also checked the dangoproject website.can any one simply explain me how to do this.Thank you in Advance
email.html
<html>
<head>
</head>
<body>
<form action="." method=POST>
enter email<input type =text name="email">
<input type=submit value="submit">
</form>
</body>
</html>
models.py
from django.db import models
class ferpost(models.Model):
useremail=models.CharField(max_length=50)
views.py
from django.http import HttpResponse
from django.shortcuts import render_to_response
def ind(request):
name=request.POST["form-email"]
print name
return render_to_response('email.html')
urls.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'webapp1.views.home', name='home'),
# url(r'^webapp1/', include('webapp1.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
url(r'^$','app1.views.ind'),
)
settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
#Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'app1',#this is my app name
)
Get the email from POST data (querydictionary), save it your model class and you are done.
In your view