Answer the question
In order to leave comments, you need to log in
How to import a class from another Django application?
Actually the problem:
There is an application in jung called 'stats' (the purpose of the application is to pull values from the database and connect it when necessary)
This is what the view looks like, to which I need global access in the entire project
stats views.py
class ShowStats(View):
def get(self,request):
if request.user.is_authenticated:
global auser,UserGold ,UserKnights,UserXp,UserEnergy,UserPower,UserLevel,status,xpfl,progress
auser = request.user.id
GetStat = UserAttribute.objects.filter(user_id = auser)
for s in GetStat:
UserPower = s.power
UserGold = s.gold
UserKnights = s.knights
UserXp = s.xp
UserLevel = s.level
UserEnergy = s.energy
status = s.isComplete
mylvl = UserLVL.objects.raw("SELECT lvl FROM userlevel_userlvl WHERE lvlxp - {}<=0".format(UserXp))
for j in mylvl:
cl = j.lvl
xpforlevel = UserLVL.objects.raw("SELECT lvl,lvlxp FROM userlevel_userlvl WHERE lvl={}".format(UserLevel))
for k in xpforlevel:
xpfl = k.lvlxp
if UserXp >= xpfl:
UserAttribute.objects.filter(user_id=auser).update(level=F('level')+1,xp=F('xp')-UserXp)
progress = decimal.Decimal(round((UserXp/xpfl)*100,0))
#setLevel = UserAttribute.objects.filter(user_id = auser).update(level=cl)
return auser,UserGold,UserKnights,UserXp,UserLevel,UserEnergy,UserPower,status,xpfl,progress
else:
return redirect('index')
from game.views import ShowStats
class FarmIndex(View):
def get(self,request):
usr = request.user.id
ShowStats.get(self,request)
context = {
'UserGold':UserGold,'UserKnights':UserKnights,'UserXp':UserXp,'UserLevel':UserLevel,
'UserEnergy':UserEnergy,'UserPower':UserPower,'status':status,'xpfl':xpfl,'progress':progress,
}
return render(request,'farm.html',context)
if request.user.is_authenticated:
returns False at the beginning. I Answer the question
In order to leave comments, you need to log in
Something with the design of the code you generally have trouble ...
Why globals? Have you heard of pep8? The very naming of variables, and the code itself...
Move the logic into a separate function, import it and use it in your views...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question