ich versuche derzeit mit Hilfe des Django-Frameworks Daten in einer Tabelle zu speichern.
meine Anwendung in meinem Prjekt sollte aus zwei Seiten bestehen a) Oberfläche für die Anmeldung b) Oberfläche zur Dateneingabe
Ich habe derzeit nur a)
meine models.py
Code: Alles auswählen
from django.core import exceptions
from django.db import models
from django import forms
from django.conf import settings
from django.db import connections
from datetime import datetime
from time import strftime
__version__="1.0"
class UnixTimestampField(models.DateTimeField):
def __init__(self, null = False, blank = False, **kwargs ):
super(UnixTimestampField, self).__init__(**kwargs)
self.blank, self.isnull = blank, null
self.null = True #'prevents framework from showing in not null
def db_type(self):
# if settings.DATABASE_ENGINE == 'mysql':
typ=['TIMESTAMP']
if self.isnull:
typ+= ['NULL']
if self.auto_created:
typ+= ['default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP']
return ' '.join(typ)
#else:
# raise Exception, "NotImplementedError..."
def to_python(self,value):
if value == None:
return None
return strftime('%Y%m%d%H%M%S',value.timetuple(value))
class User(models.Model):
Name = models.CharField( max_length = 255 )
Password = models.CharField( max_length = 255 )
Timestamp = UnixTimestampField( blank = False )
def save(self, username, password):
self.Name = username
self.Password = password
super(User, self).save()
class UserForm( forms.ModelForm):
class Meta:
model = User
meine views.py
Code: Alles auswählen
# Create your views here.
from django.shortcuts import render_to_response
from django.contrib.auth import login as auth_login
from models import User
def User_Login_View(request):
return render_to_response('login.html')
def login(request):
auth_login(request)
def save(request):
if request.method =='POST':
username = request.POST['username']
password = request.POST['password']
userRowSet = User(Name=usernbame, Password=password)
userRowSet.save()
Code: Alles auswählen
from django.conf.urls.defaults import *
#from django.contrib.auth import views as auth_views
#from django.contrib.auth import urls as auth_urls
from sysbioProj01 import settings
from sysbioProj01 import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
#url(r'^%s/$'% settings.LOGIN_URL[1:], auth_views.login, {'template_name':'login.html'}, name='auth_login'),
url(r'^$', views.User_Login_View ),
url(r'^admin/$', include(admin.site.urls)),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
Code: Alles auswählen
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
<title>Login</title>
<script type="text/javascript">
<!--
$(login_form :input).tootip({
position : "center right",
offset: [-2, 10],
effect: "fade",
opacity: 0.7
});
//-->
</script>
<link rel="stylesheet" type="text/css" href="/media/style.css">
</head>
<body>
{% if form.errors %}
<p> your username or password did not match.Please try again </p>
{% endif %}
<div id="form_fields">
{% block content %}
<fieldset>
<legend>User authentification</legend>
<form id="login_form" action="#" method="post" accept-charset="utf8">
<div class="form_rows">
<label for="username">Username:</label>
<input class="a_input" id="username" title="At least 8 characters."/><br />
</div>
<div class="form_rows">
<label for="password">Password:</label>
<input class="a_input" id="password" title="Please use something hard to guess."/><br />
</div>
<div class="form_rows">
<label for="lifespan">Lifespan of session</label>
<select id="cookie_lifespan">
<option>5 days</option>
<option>6 days</option>
<option>7 days</option>
</select>
</div>
<div class="form_rows">
<input type="hidden" name="next" value="{{ next }}" />
<input type="submit" value="Login"/>
<input type="reset" value="Reset"/>
</div>
</form>
</fieldset>
</div>
{% endblock %}
</body>
</html>
lasse den Server laufen und der "sagt"
Forbidden (403)Quit the server with CONTROL-C.
[18/Jul/2011 12:33:17] "GET / HTTP/1.1" 200 1570
[18/Jul/2011 12:33:29] "POST / HTTP/1.1" 403 2326
CSRF verification failed. Request aborted.
Was habe ich vergessen?
Gruß
Franky