0

簡単な電子メールサブスクリプションプロジェクトを作成しています。電子メールテキストフィールドを持つhtmlファイルがあります。次に、入力した電子メール値をhtmlページから取得し、mysqlデータベースに保存します。先に進む方法がわかりません。iグーグルでどこでも見ましたが、iamは正しく理解できませんでした。dangoprojectのWebサイトもチェックしました。誰でも簡単にこれを行う方法を説明できます。よろしくお願いします。

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 
 )
4

1 に答える 1

0

POST データ (querydictionary) からメールを取得し、モデル クラスに保存して完了です。あなたの見解では

def ind(request):
    email = request.POST.get("email", "noting@nothing.com")
    f = ferpost(useremail=email)
    f.save()
于 2012-12-20T09:59:00.350 に答える