I am new to python and django and I am trying to allow users to enter text into a texbox and when they click post, the message should show directly below the textbox. The user can choose between private message of public message using the radio button. If public it would say "username wrote: hello" if private it would say "username whispered: hello" this is what I have so far and I am currently stuck and keep giving an error "inconsistent use of tabs and spaces in indentation (views.py, line 19)"
html template
{% extends "social/base.html" %}
{% block content %}
<div class='main'>
<form method='POST' action='/social/messages/' enctype='multipart/form-data'>
{% csrf_token %}
<h3>Type here to leave a message</h3>
<textarea name='message' cols='50' rows='3'>{{ text }}</textarea><br>
Public<input type='radio' name='public' value='0' checked='checked'>
Private<input type='radio' name='private' value='1'>
<input type='submit' value='Post Message'>
</form>
{% if text %}
{{ text }} <br style='clear:left;'><br>
{% endif %}
<br>
</div>
{% endblock %}
views.py
def messages(request):
if 'username' in request.session:
username = request.session['username']
if 'message' in request.POST
newmessage = request.POST['message']
if request.POST.get('Private', False):
privatemessage = True
else:
privatemessage = False
savemessage = Message(sender=username, message=newmessage, isItPrivate=privatemessage)
savemessage.save();
template = loader.get_template('social/messages.html')
context = RequestContext(request, {
'appname': appname,
'username': username,
'newmessage': newmessage,
'loggedin': True
})
return HttpResponse(template.render(context))
else:
raise Http404("User is not logged it, no access to messages page!")
models.py
class Message (models.Model):
sender = models.CharField(max_length=255)
message = models.CharField(max_length=255)
isItPrivate = models.CharField(max_length=255)
def _str_(self):
return self.sender
Aucun commentaire:
Enregistrer un commentaire