Я не знаю, почему это дает мне KeyError в строке: idtoken=request.session['uid']
, postCreateEquity
функция, это весь файл views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.contrib import auth
import pyrebase
config = {
'apiKey': "AIzaSyCQotYTbJ_W3ezUNc99JGDociFfAIp2-n8",
'authDomain': "efund-c.firebaseapp.com",
'databaseURL': "https://efund-c.firebaseio.com",
'projectId': "efund-c",
'storageBucket': "efund-c.appspot.com",
'messagingSenderId': "67104720448"
}
firebase= pyrebase.initialize_app(config)
authe = firebase.auth()
database=firebase.database()
def login(request):
return render (request,'login.html')
def postlogin(request):
email=request.POST.get('email')
passw=request.POST.get('pass')
try:
user=authe.sign_in_with_email_and_password(email,passw) #we named auth to authe because we used auth library
except:
message="Invalid credentials"
return render(request,'welcomepage/login.html',{"messg": message})
print(user['idToken'])
session_id=user['idToken']
request.session['uid']=str(session_id)
return render (request,'welcomepage/efand-welcome-registered-user.html',{"e":email})
def postlogout(request):
auth.logout(request)
return render(request,'welcomepage/login.html')
def signUp(request):
return render(request,'signup.html')
def postsignup(request):
firstName=request.POST.get('signupfirstusername')
lastName=request.POST.get('signuplastusername')
email=request.POST.get('signupemail')
password=request.POST.get('signuppassword')
vpassw=request.POST.get('signupverifiedpassword')
birthday=request.POST.get('signupdob')
country=request.POST.get('signupcountry')
checkbox=request.POST.get('signupcheckbox')
user=authe.create_user_with_email_and_password(email,password)
uid=user['localId'] #this id is unique for everyone
data={"firstName":firstName,"lastName":lastName ,"birthday":birthday ,"country":country,"checkbox":checkbox}
database.child("Users").child(uid).set(data)
return render(request,'welcomepage/login.html')
def startCampaign(request):
return render(request,'welcomepage/start-campain-registered-user.html')
def createEquity(request):
return render(request,'welcomepage/efund-createEquity-registered-user.html')
def createReward(request):
return render(request,'welcomepage/efund-createReward-registered-user.html')
def postCreateEquity(request):
category=request.POST.get('category')
duration=request.POST.get('duration')
highlight=request.POST.get('heighlight')
imgName=request.POST.get('img')
investDiscussion=request.POST.get('investDiscussion')
investTerms=request.POST.get('investterms')
linkForVideo=request.POST.get('video')
market=request.POST.get('market')
name=request.POST.get('name')
neededMoney=request.POST.get('amountofmoney')
endDate=request.POST.get('enddate')
offers=request.POST.get('offers')
startDate=request.POST.get('startdate')
summary=request.POST.get('summary')
team=request.POST.get('team')
timeline=request.POST.get('timeline')
idtoken=request.session['uid']
a= authe.get_account_info(idtoken)
a=a['users']
a=a[0]
a=a['localId']
print(str(a))
data={"category":category,"imgName":imgName,"duration":duration,"highlight":highlight,
"investDiscussion":investDiscussion,"investTerms":investTerms,"linkForVideo":linkForVideo,
"market":market,"name":name,"neededMoney":neededMoney,"endDate":endDate,"offers":offers,
"startDate":startDate,"summary":summary,"team":team,"timeline":timeline}
# idcamp=request.POST.get('signupfirstusername')
# idcreator=request.POST.get('signupfirstusername')
database.child('Equity Campaign').child(a).set(data)
return render(request,'welcomepage/efand-welcome-registered-user.html')