- Iniciando projeto:
django-admin startproject NOME_DO_PROJETO
- Adicionando módulos:
django-admin startapp NOME_DO_MODULO
- Instalado o djangorestframework
pip install djangorestframework
- Adiciona os módulos ao projeto (nome_projeto/settings.py)
- Cria as migrations
py manage.py makemigrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/Components/create-profile/CreateProfile.js | |
// importações | |
// Importando ação que realizará o envio | |
import { connect } from 'react-redux' | |
import { withRouter } from 'react-router-dom' | |
import { createProfile } from '../actions/profileActions' | |
class CreateProfile extends Component { | |
// Estado |
doc.: https://docs.djangoproject.com/en/2.1/topics/forms/modelforms
class AddressForm(forms.ModelForm):
class Meta:
model = Address
# fields = '__all__'
fields = ('address', 'address_complement', 'city', 'state', 'country')
widgets = {
'address': forms.TextInput(attrs={'class': 'form-control'}),
from django.contrib.auth.models import User
from rest_framework import serializers
from .models import Category, Product
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('first_name', 'last_name', 'email')
REST_FRAMEWORK = {
# ...
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication', # Necessário adicionar 'rest_framework.authtoken' ao INSTALLED_APPS
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import RedirectView
# 301 - permanente (browser salva como cache destino)
# 302 - temporário
class LogoutRedirectView(RedirectView):
url = '/login/'