我正在制作一个简单的电子邮件订阅项目。我有一个包含电子邮件文本字段的 html 文件。现在我想从 html 页面获取输入的电子邮件值并将其存储在 mysql 数据库中。我不知道如何继续。我谷歌搜索并到处看到,但我无法正确理解。我还检查了 dangoproject 网站。任何人都可以简单地解释我如何做到这一点。谢谢你提前
电子邮件.html
<html>
<head>
</head>
<body>
<form action="." method=POST>
enter email<input type =text name="email">
<input type=submit value="submit">
</form>
</body>
</html>
模型.py
from django.db import models
class ferpost(models.Model):
useremail=models.CharField(max_length=50)
视图.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')
网址.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'),
)
设置.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
)