#django

/

      • gacrux joined the channel
      • gacrux has quit
      • o0 joined the channel
      • pm2 joined the channel
      • converge joined the channel
      • o0 has quit
      • zeus1 has quit
      • pm2
        What's the best way to integrate a django backend with a vue front end? Should I have django serve a single template to host the single-page app? Or run the django project on a separate server from the vue content?
      • I'm currently trying to host my vue app separately, and have my django app on a separate subdomain (api.mysite.com). I'm not sure how to handle CSRF protection in that case.
      • slav0nic has quit
      • ashc joined the channel
      • Debnet joined the channel
      • shangxiao joined the channel
      • shangxiao has quit
      • fikka joined the channel
      • rpkilby joined the channel
      • iamriel joined the channel
      • kloudi- joined the channel
      • fikka has quit
      • rpkilby has quit
      • kloudi has quit
      • iamriel has quit
      • newdimension has quit
      • shangxiao joined the channel
      • newdimension joined the channel
      • gacrux joined the channel
      • kooldude joined the channel
      • shangxiao has quit
      • gacrux has quit
      • jessamynsmith
        pm2: people don't usually use csrf on api requests
      • pm2: you have other mechanisms, like cors and auth tokens
      • (or whatever auth mechanism your api requests are using)
      • pm2 has quit
      • newdimension has quit
      • zeus1 joined the channel
      • jessamynsmith has quit
      • littlebit1 joined the channel
      • littlebit has quit
      • littlebit1 is now known as littlebit
      • hvyk joined the channel
      • jessamynsmith joined the channel
      • jessamynsmith has quit
      • bayman joined the channel
      • fikka joined the channel
      • BigJono joined the channel
      • iamriel joined the channel
      • zeus1 has quit
      • iamriel has quit
      • fikka has quit
      • iamriel joined the channel
      • tdy has quit
      • rns_ has quit
      • kapil___ joined the channel
      • miz- joined the channel
      • bayman has quit
      • miz- has quit
      • jessamynsmith joined the channel
      • littlebit1 joined the channel
      • wildlander has quit
      • littlebit has quit
      • littlebit1 is now known as littlebit
      • zeus1 joined the channel
      • rajesh joined the channel
      • Dunedan joined the channel
      • Dunedan_ has quit
      • newdimension joined the channel
      • Leeds joined the channel
      • zeus1 has quit
      • hvyk has quit
      • amirpro joined the channel
      • squaresandcubes joined the channel
      • squaresandcubes
        what would be the django equivalent of rails 'belongs_to :related, polymorphic: true' ??
      • jessamynsmith has quit
      • amirpro has quit
      • birdbolt1
        when using STATIC_URL and {% load static %} as seen here: https://docs.djangoproject.com/en/2.1/howto/sta...
      • I dont need to tell nginx in its config a directory to go find static content do i?
      • tdy joined the channel
      • nvm i've found my answer, i'd need to do that regardless.
      • FunkyBob
        birdbolt1: nginx needs to know to look for STATIC_URL/* inside STATIC_ROOT/
      • birdbolt1
        I'm then wondering. Before I started messing with django, I i had not pointed nginx at any directory for static files. I simply had it talking to django upstream through uwsgi
      • and was able to show default django page, sign the little images it has
      • FunkyBob
        birdbolt1: you'd never giving nginx a 'root' directive?
      • birdbolt1: did you configure uwsgi to serve your static assets?
      • or perhaps you configured Django to, which is a waste of your uwsgi resources
      • birdbolt1
        nope, not at all
      • FunkyBob
        [uwsgi and nginx can serve your static assets much more efficiently than django]
      • so Admin always worked fine?
      • birdbolt1
        i used the official tutorial here in fact https://uwsgi-docs.readthedocs.io/en/latest/tut...
      • if you ctrl-f "# mysite_nginx.conf"
      • I left it as it was it without setting real paths
      • FunkyBob
        see those two "location" directives?
      • that's telling it to serve your static and media directories [aka. STATIC_ROOT and MEDIA_ROOT]
      • birdbolt1
        yes, but iirc I left it as is, and the "/path/to/your" parent folders did not exist on my filesystem
      • FunkyBob
        well, I don't know what to tell you... _something_ is serving your static assets
      • birdbolt1
        I may be remembering wrong, but it just occured to me today as i was struggling with my js/css. I finally got it working, but was wondering how it worked before, when supposedly I never set those paths
      • FunkyBob
        what is your STATIC_URL and STATIC_ROOT settings set to?
      • birdbolt1
        STATIC_URL: /static/
      • backnforth joined the channel
      • FunkyBob
        hence "location /static" for nginx
      • (although I prefer to use try-files)
      • birdbolt1
        STATIC_ROOT=os.path.join(BASE_DIR, "assets/bundles/")
      • FunkyBob
        well, that's probably wrong, then
      • STATIC_ROOT should point to where nginx serves STATIC_URL from... and typically that's NOT inside your project
      • you use "manage.py collectstatic" to copy all your static assets into STATIC_ROOT
      • birdbolt1
        the assets/bundles/ is for webpack, and i was able to get it working today by pointing nginx to that directory. I just couldnt figure out why it didnt work like the default django page. (beleiving i never set the paths to static dir in nginx's config, i assumed uwsgi relayed the files ro something)
      • FunkyBob
        so is "assets/bundles" where your JS build pipeline dumps its output?
      • right
      • birdbolt1
        yes ^
      • FunkyBob
        but now you won't get any of the Admin assets, or static from any other installed apps
      • birdbolt1
        I'm still learning django, and not sure where the admin tools come into play (whether dev or prod environment)
      • FunkyBob
        now, it IS ok for you to use that dir as your STATIC_ROOT... just remember (a) run manage.py collectstatic... and (B) don't add it to source control
      • Admin is a handy DB admin tool...
      • birdbolt1
        The explanations i'm seeing for it online are coming off as vague. Not telling me when i use it
      • FunkyBob
        but it's a good example of an app providing its own static assets [css, js, images]
      • if you haven't used admin, you clearly have not done the Django tutoria.... why not??
      • birdbolt1
        yes, for me as a dev during development? or when the server is running, do i get to log into it from where its serving in production? or for a user? i dont get it
      • I only did the polls app
      • FunkyBob
        in development, you won't use nginx, or uwsgi... or run collectstatic
      • fikka joined the channel
      • as for admin... yeah, you won't let average users int oit... and ideally you've written your site with a management interface, so Admin is only there for diving in to fix data, etc
      • birdbolt1
        alright adding admin tutorials to the top of my todo list
      • FunkyBob
        if you did the polls app, you've used admin
      • my point is this:
      • in your project, any app might be providing static assets... Django supports this
      • in development, Django helps by "runserver" serving these assets for you
      • when it comes deploy time, the "manage.py collectstatic" command gathers them all into the STATIC_ROOT directory
      • your project can also list other, non-app sources of static assets using STATICFILES_DIRS list
      • pangolin_ joined the channel
      • birdbolt1
        i ran that earlier yesterday, and it added a boatload of files to /bundles/admin.
      • FunkyBob
        when deployed, you need to configure something-other-than-django to serve STATIC_URL/* from STATIC_ROOT
      • yes, because that's where you told it to put them
      • that's what STATIC_ROOT says
      • birdbolt1
        ahh so you said ealier nginx-uwsgi are betetr at serving static files than django is, is this where they coem into play?
      • FunkyBob
        03:17 <+FunkyBob> when deployed, you need to configure something-other-than-django to serve STATIC_URL/* from STATIC_ROOT
      • that "something other than django" would be nginx or uwsgi in this case, yes
      • MarkusH has quit
      • uwsgi can actually be quite efficient at handling static assets, if you configure it to run offload-threads
      • fikka has quit
      • mRWaffles has quit
      • MarkusH joined the channel
      • birdbolt1
        earlier today, i made the following change to my nginc config:
      • location /static {
      • alias /path/to/assets/bundles/
      • and it works.
      • I believe nginx effectively serving the js and css now, instead of django, right?
      • FunkyBob
        sounds like it, yes
      • compare the uwsgi and nginx logs
      • birdbolt1
        I will look into moving this role to uwsgi, once i understand static file handling better. Adding to my TODO list as well
      • zeus1 joined the channel
      • FunkyBob
        if you move it to uwsgi, you might not need nginx any more :P