在 Django (Python) 中需要电子邮件订阅方面的帮助



im 制作一个简单的电子邮件订阅项目.我有一个 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>

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 
 )

从POST数据(查询字典)中获取电子邮件,将其保存为模型类,您就完成了。在您看来

def ind(request):
    email = request.POST.get("email", "noting@nothing.com")
    f = ferpost(useremail=email)
    f.save()

相关内容

最新更新