These are chat archives for django/django

26th
Feb 2018
Roel
@roelzkie15
Feb 26 2018 02:55

@sabin20 I do not know about react but in angular you need to run a different server for the client app and the django app. Yyou only need to create a consumable Rest Api using django-rest-framework which i prefer in your back end, map that endpoint for your client to consume via http request.

The main architecture here is to separate the client side to server side. Do not use a single app although this is also possible (tried it in angular but i prefer to seperate server from client side). It is also possible for mobile app to consume those apis thats another benefits. But make sure to look out for CORS but django-cors-header has a solution for that.

It means setting up a SPA like angular/react with django means you have to give up the templating engine of django, you give up using the traditional workflow of django. But that is not an issue. You only need to use django to list, create, delete, update, view a record. Rest API is merely a representation (GET) and manupulation (POST) of data.

It is very easy. I suppose looking to google, there are bunch of guys that already did that, you can also talk to @elcolie saw his repo in github to be a react guy.

@sabin20 another one i dislike visual studio, just use their vscode instead.
Sanjeev Sharma
@thesanjeevsharma
Feb 26 2018 14:13
def downloadChemical(request):
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename=operator.csv'

    writer = csv.writer(response)
    writer.writerow(["Date", "Time", "Operator", "Innoculant", "Drying Agent Required", "Actual Drying Agent"])

    operator_name = request.session['operator']

    comp_data = db.get(request.session['uid']).each()
    count = 0
    operators = []
    for chota_db in comp_data:
        if count == 1:
            operator = chota_db.val()
            break
        else:
            count += 1
    for key, value in operator.items():
        for k, v in value.items():
            if v['operatorId'] == operator_name:
                writer.writerow([str(key), str(k), str(v['operatorId']), str(v['innoculant']), str(v["dryingAgentRequired"]), str(v["dryingAgentActual"])])

    return response
This code works on local host but not on pythonanywhere. I am trying to download the displayed db. Anyone?
Ghost
@ghost~5a7e8880d73408ce4f8c8315
Feb 26 2018 15:13
Anyone used background_tasks??
Prateek Dabas
@dprateek11
Feb 26 2018 18:24
hello everyone
i am stuck at something
i wanted to get the id of user logged into admin
i have tried these
def get_user_id(request):
print request.user.id
its not giving me any error as well as not printing anything
i have tried this above link also but i am not getting anything