Aprendendo computação com Python
Pycubator
Python para Zumbis
Aprendendo Python em 10 minutos (en)
# Criando novo post
>>> Post.objects.create(title="Post Test", body="Content")
# Buscando todos os posts no banco de dados
>>> Post.objects.all()
[<Post: Post Test>]
# Pesquisando determinado post a partir do seu título
>>> post = Post.objects.get(title="Post Test")
# Exibindo o valor do atributo 'title'
>>> post.title
Post Test
# Atualizando título do post
>>> post.title = "Post Updated"
>>> post.save()
# Removendo post
>>> post.delete()
>>> Post.objects.all()
[]
from django.conf.urls import url
from . import views
urlpatterns = [
# ex: /polls/
url(r'^$', views.index, name='index'),
# ex: /polls/5/
url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
# ex: /polls/5/results/
url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
# ex: /polls/5/vote/
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
def index(request):
latest_question_list = Post.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'post/index.html', context)
def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)
def results(request, question_id):
response = "You're looking at the results of question %s."
return HttpResponse(response % question_id)
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
<ul>
<li><a href="/polls/1/">Qual é a melhor palestra no FLISOL 2016?</a></li>
<li><a href="/polls/2/">Como foi a recepção no evento?</a></li>
<li><a href="/polls/3/">A localização do evento está boa para você?</a></li>
</ul>
<form action="/your-name/" method="post">
<label for="your_name">Your name: </label>
<input id="your_name" type="text" name="your_name" value="{{ current_name }}">
<input type="submit" value="OK">
</form>
from django import forms
class NameForm(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
<form action="/your-name/" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="sdalkj23109da...">
<p>
<label for="your_name">Your name: </label>
<input id="your_name" type="text" name="your_name" maxlength="100">
</p>
<input type="submit" value="Submit" />
</form>
Sistema de Enquetes
django.contrib.auth
django.contrib.admin
Login
Tela Inicial
Listagem de Registros
Cadastro