#django

/

      • sunil_bansal has quit
      • thiras joined the channel
      • novigradian has quit
      • nimomo joined the channel
      • jas02 joined the channel
      • Lenz has quit
      • Kangermu joined the channel
      • BPL joined the channel
      • chasonchaffin joined the channel
      • READ10 joined the channel
      • JuanDaugherty joined the channel
      • blip99 joined the channel
      • chasonchaffin has quit
      • NomadJim_ has quit
      • zhalla_ joined the channel
      • NomadJim_ joined the channel
      • chasonchaffin joined the channel
      • alrondo has quit
      • lacrymology has quit
      • valerio joined the channel
      • fikka has quit
      • Genitrust joined the channel
      • majd has quit
      • jas02 joined the channel
      • chasonchaffin has quit
      • fikka joined the channel
      • Lenz joined the channel
      • marcosmoyano joined the channel
      • pwrentch joined the channel
      • saltjolt joined the channel
      • GraysonBriggs joined the channel
      • danpalmer joined the channel
      • gmonnerat has quit
      • techno_x64 joined the channel
      • chasonchaffin joined the channel
      • shredding has quit
      • blip99 has quit
      • Mrloafbot_ joined the channel
      • fikka has quit
      • sunil_bansal joined the channel
      • aditya_r has quit
      • aditya_r joined the channel
      • chasonchaffin has quit
      • av_ has quit
      • av__ is now known as av_
      • chasonchaffin joined the channel
      • jas02 joined the channel
      • sunil_bansal has quit
      • n0nam3 has quit
      • geetar joined the channel
      • Fuyou has quit
      • Ahuj has quit
      • chasonchaffin has quit
      • fikka joined the channel
      • Kangermu has quit
      • nnscr joined the channel
      • nnscr
        hello! question: have a request object. need a response object (say to "simulate" a http request). how to achieve that? :D
      • fikka has quit
      • knbk
        nnscr: that depends on your requirements, but one option is to simply call a view function
      • nnscr
        knbk: yep, but that doesn't really seem clean. i need it a step further
      • and that's already all of my requirements. resolve request to response object
      • moldy
        that is exactly what a view's job is
      • rgenito joined the channel
      • nnscr
        oh and it should work with django rest framework, but i assume that that shouldn't make a difference
      • knbk
        what do you mean with a step further?
      • rgenito is now known as Guest31727
      • nnscr
        well, something like process_request(request) -> Response ^^
      • moldy
        so, not sure why you think that's unclean. what is your higher level requirement?
      • nnscr
        it's fine if i need to call the view, it just seems a bit unclean
      • but probably i'm just beeing too picky again
      • moldy
        what kind of response do you want?
      • fikka joined the channel
      • Lynoure
        nnscr: why do you want such a thing as non-view? :)
      • nnscr: I mean, what's the use case?
      • nnscr
        uh, a http response i guess? :D with headers, response code, body and so on... ^^
      • svg
        I'm trying to find a good explanation of what exactly 'app_label' is, how it's created (autmagically?) and what use caes it has.
      • moldy
        nnscr: we can really help you much better if you tell us what your actual (high-level) problem is
      • knbk
        response = HttpResponse('') <-- that should do it, then?
      • moldy
        nnscr: otherwise, my best answer is: ``def process_request(request): return HttpResponse()``
      • Beef_wgtn
        Is there an easy way to migrate app data from MySQL to Postgres? Including user data?
      • Genitrust has quit
      • nnscr
        having a dict (from json) that contains the http verb and url and needing the response as if a browser would have called it directly
      • zeus1 has quit
      • negaduck joined the channel
      • moldy
        Beef_wgtn: depends on the details. dumpdata / loaddata might work.
      • Lynoure
        nnscr: sounds like you are mocking a rest API for documentation...
      • felixx has quit
      • Beef_wgtn
        moldy: thanks I just found a relevant post on that. Cheers
      • nnscr
        Lynoure: nah, i'm trying to call a rest api from a channels websocket, actually
      • FunnyHeretic has left the channel
      • moldy
        nnscr: any reason in particular why you don't want to perform a real http request?
      • chasonchaffin joined the channel
      • danner joined the channel
      • nnscr
        moldy: i was just playing around with channels and thought that would be something cool to do... ^^ we're about to develop a SPA with django as a backend and wanted to avoid the tcp, http overhead
      • Guest31727 has quit
      • knbk
        svg: it's a unique identifier for an app in INSTALLED_APPS, it defaults to the innermost module containing models.py, e.g. for apps.core.models it's 'core'
      • nnscr
        i know it's not much and doesn't really matter, i just haven't expected it to be that hard
      • Genitrust joined the channel
      • Lynoure
        nnscr: I suspect this is only hard because of the artificial limitations (see e.g. knbk's answer or moldy's)
      • nnscr
        i'm coming from the symfony environment and passing in a request somewhere to directly get a response without ever seeing who returned the response is a no brainer there
      • moldy
        nnscr: if you have a ReST API, it's designed to be used via HTTP, not as a direct python API.
      • jerojasro joined the channel
      • svg
        knbk, thanks
      • jerojasro has quit
      • aditya_r has quit
      • jerojasro joined the channel
      • nnscr
        moldy: yep, but even if it wasn't a rest api, i think there would still be use cases to render a view manually
      • moldy
        nnscr: i think your real problem is how to **construct the request**? if so, take a look at RequestFactory(). i'd probably just use the `requests` lib to perform an actual HTTP request, though.
      • nnscr
        but i don't want to argue with you guys, i'm fairly new to django and i guess i just don't understand it yet
      • svg
        is there a way to find out which other apps (besides the ones I specifically write myself) need access to the database? I'm looking at two apps with their own db, and writing a db router
      • moldy
        nnscr: a view is just a callable, you can call it like any other python callable: ``response = myview(request)``
      • nnscr
        moldy: yep, i know, thanks. does that also work for class based views?
      • chasonchaffin has quit
      • moldy
        nnscr: it works on the result of calling .as_view(), yes: `´myview = MyCBV.as_view(); response = myview(request)``
      • nasusiro has quit
      • knbk
        note that doing this would skip middleware etc.
      • moldy
        strictly speaking, class-based views are not views. the result of calling ``._as_view()`` is the actual view.
      • nnscr
        moldy: so i can't just use resolve(url) and call the result no matter if it's an class or function view?
      • knbk: okay... that doesn't sound good
      • moldy: alright, good to know
      • moldy
        what knbk says, plus you bypass the webserver in front of your app and whatnot
      • knbk
        nnscr: ``func, args, kwargs = resolve(url); response = func(request, *args, **kwargs)`` works for any kind of view
      • nnscr
        i don't care if i bypass the webserver. but i'd like to have a close as possible stack as when doing a regular request
      • moldy
        just use requests and do a real http request, or split your ReST api into a python and an http part
      • nnscr
        moldy: that's not an option. right now i'm just playing around with django and see how comfortable i feel with it. doing this manually-calling-rest-thing is just for science, actually
      • moldy
        ok, then knbk gave you the recipe
      • nnscr
        yeah, i've already did it that way and it worked okay. just thought there would be a better way
      • including middleware for example
      • knbk
        it's generally a bad idea, that's why Django doesn't make it easy
      • (there's the test client which calls middleware, but it's for testing only and full of security holes)
      • nnscr
        well, symfony has something called sub-requests where you can pass a custom request in to the kernel which delivers you a response in return (not that i'd want to start a framework war)
      • (there are reasons i'm leaving the php world for web development after all ^^)
      • i agree that it has limited use cases, but still i thought it should be possible somehow. but however, i'll just use the view directly for the moment and think of something else when we actually start the project
      • thank you guys anyway!
      • techno_x64 has quit
      • jadajada joined the channel
      • dethos joined the channel
      • techno_x64 joined the channel
      • jeffspeff joined the channel
      • k0mpa joined the channel
      • chasonchaffin joined the channel
      • cubillosxy_py joined the channel
      • chasonchaffin has quit
      • valerio has quit
      • thiras has quit
      • birdbolt1 joined the channel
      • birdbolt1
        hallo
      • I'm reading through https://docs.djangoproject.com/en/2.0/topics/se... and there is constant reference to a certain "proxy"
      • what is this proxy? wsgi?
      • or like an apache server?