|
Thermopyle posted:When you capture a group in an url regex it gets passed to the view which is the second parameter of the url function. It looks like either django or DRF is choking on this unexpected group getting passed to it. Ooooh. Duh, that makes sense. I was using the parentheses in a mathematical context. I thought that I read about the trailing slash somewhere in the documentation. Is there a case where it wouldn't automatically be redirected to the proper url regardless of slash? (I remember some times when it didn't do this, but I have no idea what settings I had...)
|
# ? Nov 9, 2014 20:16 |
|
|
# ? May 16, 2024 18:48 |
|
Ok, so I think I'm doing this wrong but I was hoping for some confirmation. I'm writing a generic survey application that has dynamically generated forms. These forms are built off a set of questions which can store an indiscriminate data type in a given section/page/whatever. Questions also have validators. They can use the built in validators but also a set of custom validators. One of the validators I've built tests against the value of other fields in the form. The way that I'm doing it is to subclass forms.CharField and override clean() and run_validators() to pass the form to the validator so I can test the other field against the field being validated. I feel like this is a dangerous pattern because I know Django fields are designed so they don't know anything about the form that they're part of. Can anyone suggest a better way to do this? I can provide more information if anything is unclear.
|
# ? Nov 9, 2014 21:28 |
|
This has been tripping me up so often lately that I'm starting to wonder if I have a workflow issue or if I'm the only one using django migrations https://code.djangoproject.com/ticket/23410 How the heck are you supposed to work on/test a migration (ie data migration) if you can't reliably roll it backwards/forwards without random other apps rolling back too?
|
# ? Nov 10, 2014 21:18 |
|
Thermopyle posted:For my own question....has anyone dealt with handling a writable GenericForeignKey in django-rest-framework? I can get a readable hyperlinked representation like so: To answer my own question: Python code:
So anyway, this overriden `restore_fields` method will look up the object referenced by a hyperlink POST'ed to the content_object field and do the right thing with it. It won't allow you to POST in the browsable API, but I'm not sure how that would work anyway, as the select box normally used for related fields would have to be populated with every object from every model in your project... It took me a lot of tracing with the PyCharm debugger to figure this out. I really wish there was something like ccbv for DRF.
|
# ? Nov 10, 2014 23:57 |
|
I was just trying to figure out all the configured urls in my project. It can get confusing if you're using several third party apps that configure their own urls. So, I whipped this together to print out a list of all the urls. https://gist.github.com/dmwyatt/4ef6a34874a01d9f3ffb
|
# ? Nov 18, 2014 00:24 |
|
Thermopyle posted:I was just trying to figure out all the configured urls in my project. It can get confusing if you're using several third party apps that configure their own urls. `pip install django_extensions` `python manage.py show_urls` I've used it when coming onboard a large project I'm unfamiliar with, on more than one occasion.
|
# ? Nov 18, 2014 08:11 |
|
I'm working on an application that runs a few different sites using the same codebase. The differences between the sites are mostly cosmetic, but there are site-specific terms that need to be enforced e.g. site1.com/clients/ site2.com/members/ - both resolve to the same view. The url pattern looks something like url(r'^%s/' % config.member_text, view stuff, namespace stuff) This is fine running separate django instances since the url patterns can be set by a config setting when the instance is started. I've been tasked with running these sites (and more to come in the future) off of a single instance. The problem is the urls are set on application start, so they can't be dynamic per request. Is there some way to make this type of setup work?
|
# ? Nov 18, 2014 18:19 |
|
Yay posted:Not to diminish what you did, but future-you may appreciate: Oh, durr. ---------- New question. I'm doing a single page app with a backend API built with django-rest-framework. I'm thinking about hosting and I'm having a hard time deciding how to do it. I serve stuff from S3 with Heroku-hosted Django all the time, but I don't think this would work with my SPA setup since my HTML and JS would be coming from the amazon domain and wouldn't work because of Same Origin Policy. I haven't really messed with hosting static stuff directly fro Heroku, but my understanding is this is heavily discouraged because of (I guess) performance issues. What kind of hosting are people using for Django-backed single page apps?
|
# ? Nov 20, 2014 23:55 |
|
Thermopyle posted:Oh, durr. Just because it's a single page app doesn't mean you have to serve it as a static file. Just run it as a single view out of Django/Heroku.
|
# ? Nov 20, 2014 23:59 |
|
Ahz posted:Just because it's a single page app doesn't mean you have to serve it as a static file. Just run it as a single view out of Django/Heroku. Yeah, I obviously need to do some profiling, but my understanding is there are performance benefits to serving as a static file and avoiding the Django view machinery.
|
# ? Nov 21, 2014 00:01 |
|
I would bet that any performance loss from serving a single essentially static template out of Django vs. AWS would be dwarfed by the req/res cycles of your REST requests / DB hits post-initial-load. Just a guess.
|
# ? Nov 21, 2014 00:07 |
|
Ahz posted:I would bet that any performance loss from serving a single essentially static template out of Django vs. AWS would be dwarfed by the req/res cycles of your REST requests / DB hits post-initial-load. Yeah, this is a good point.
|
# ? Nov 21, 2014 00:10 |
|
I've been developing a blogging engine on Django 1.7 and I'm wondering if I'm falling into a anti-pattern / pitfall I'm passing each blog into the template engine, and then using its pk value in the HTML id attribute. code:
Is using the pk value in the HTML id attribute a potential pitfall, or am I over blowing things? Is there a better way, on a page with multiple blogs, to attach event listeners to capture the event on a specific blog without doing as I have done?
|
# ? Nov 22, 2014 10:50 |
|
I have a custom 500.html template that gets returned when the server shits the bed. How should I go about testing the view to make sure the template gets sent on server errors? The obvious answer is create a server error, but I've worked pretty hard to make that not possible and I'm wondering if there is an easy way to mock it or something?
|
# ? Nov 23, 2014 04:01 |
|
Shut down your database?
|
# ? Nov 23, 2014 04:10 |
|
In your unit test (you are doing those, right?) create a response object and set the code to 500 then pass it to your view.
|
# ? Nov 23, 2014 04:50 |
|
Blinkz0rz posted:In your unit test (you are doing those, right?) create a response object and set the code to 500 then pass it to your view. Yeah, the question was about my unit tests. I don't know why I didn't think of this, thank you.
|
# ? Nov 23, 2014 04:56 |
|
duck hunt posted:I've been developing a blogging engine on Django 1.7 and I'm wondering if I'm falling into a anti-pattern / pitfall If you were using Django forms, you could have the ID automatically set into the form with a hidden field widget. It's a bit odd and counter productive to parse the submit id after posting unless you plan to use the ID for something on the page itself like javascript/css. If you wanted to use the ID in those cases, you could use the form.field.id_for_label attribute to automatically spit out the id with a relevant unique html id.
|
# ? Nov 23, 2014 06:13 |
|
Thanks for the idea. I will do give that a shot on my forms. Even though in the code example I gave, I was showing a submit button, the {{ blog.id }} as a HTML attribute is mostly being used to allow for efficient document.getElementById() type code, and yes, like you mentioned, some CSS too.
|
# ? Nov 23, 2014 07:56 |
|
Aw poop. When I do code:
code:
|
# ? Nov 24, 2014 01:43 |
|
Storgar posted:Aw poop. When I do What version of django are you on and what does your file structure look like? Also, make sure you've got an __init__.py in the folder the tests are in.
|
# ? Nov 24, 2014 02:08 |
|
Django stupidly needs at least one model defined in the app for it to consider the app as something that can be tested. If your app doesn't have models you can trick it by putting a models.py file in the root of the app.
|
# ? Nov 24, 2014 03:20 |
|
Blinkz0rz posted:Django stupidly needs at least one model defined in the app for it to consider the app as something that can be tested. If your app doesn't have models you can trick it by putting a models.py file in the root of the app. Is that the case with 1.7? I know they revamped how apps work...
|
# ? Nov 24, 2014 04:42 |
|
Oops, forgot to say. I'm using Django 1.7. Folder structure is like this: code:
The March Hare posted:What version of django are you on and what does your file structure look like? Also, make sure you've got an __init__.py in the folder the tests are in. That was it. I put an __init__.py in the "/app" folder and it works now. Thanks guys!
|
# ? Nov 24, 2014 04:57 |
|
Thermopyle posted:Is that the case with 1.7? I know they revamped how apps work...
|
# ? Nov 24, 2014 07:45 |
|
The March Hare posted:Yeah, the question was about my unit tests. I don't know why I didn't think of this, thank you. As a followup to this, I just found out that django.http has a thing called HttpResponseServerError which is just an HttpResponse w/ a 500 status code by default. Which means I can just do: code:
The March Hare fucked around with this message at 18:03 on Nov 24, 2014 |
# ? Nov 24, 2014 17:52 |
|
I just wanted to say this here because I know a lot of people read this thread who are just at the right stage in their journey to becoming the Bestest Web Programmer EVER... I finally said gently caress it and I am doing all projects going forward without using any Django forms or templates, and its been pretty great. I basically set up two projects. The Django project handles the models and provides access to them via an API built with django-rest-framework, and then in a completely separate project I develop a JS/HTML/CSS frontend. This works great for even simple sites once you've got your mind wrapped around a javascript framework or two. I like the clarity you get from the separation of concerns like this. Anyway, give it a try. It's the future.
|
# ? Nov 24, 2014 18:27 |
|
Thermopyle posted:I just wanted to say this here because I know a lot of people read this thread who are just at the right stage in their journey to becoming the Bestest Web Programmer EVER... So you handle all the navigational urls and reverse url template tags with your javascript framework? Also, does the javascript framework you're using have a name? Are they served by Django or do you have another program to do that?
|
# ? Nov 24, 2014 21:50 |
|
Storgar posted:So you handle all the navigational urls and reverse url template tags with your javascript framework? Also, does the javascript framework you're using have a name? Are they served by Django or do you have another program to do that? The only urls served by Django are like api.domain.com/api/foo/1/ and api.domain.com/api/bar. The actual site end users see has urls like domain.com/inbox and domain.com/profile. Those urls are all routed to and "created" by the javascript framework. You can use Ember, React, AngularJS, a bunch of others to do this. I prefer React. I'm doing something with AngularJS right now, so I'll point to examples for that... Taken from the AngularJS tutorial: JavaScript code:
The client app can be served by the same server Django is running on if you have access to configure the server to serve those as static files. I'm currently hosting Django on Heroku and serving my frontend from Amazon S3.
|
# ? Nov 25, 2014 00:02 |
|
Thermopyle posted:I just wanted to say this here because I know a lot of people read this thread who are just at the right stage in their journey to becoming the Bestest Web Programmer EVER...
|
# ? Nov 25, 2014 03:09 |
|
Thermopyle posted:I just wanted to say this here because I know a lot of people read this thread who are just at the right stage in their journey to becoming the Bestest Web Programmer EVER... I'd decided that I was going to try this with my next project, which is interaction-heavy for its main functionality, and this makes me feel better about my decision. Do you have a fallback in case JS no workie? Or is that just not a concern in TYOOL 2014/2015?
|
# ? Nov 25, 2014 05:16 |
|
No Wave posted:I think you're definitely right. Do you still feel like you're getting enough out of Django, or have you been tempted to use a different framework? I've got a compulsion to always be trying new things. However, in this case, I stick with Django because:
Things pushing me towards a different framework:
xpander posted:I'd decided that I was going to try this with my next project, which is interaction-heavy for its main functionality, and this makes me feel better about my decision. Do you have a fallback in case JS no workie? Or is that just not a concern in TYOOL 2014/2015? gently caress 'em (unless you've got metrics telling you they're a significant-enough portion of your audience. in that case you're the one who's hosed, because gently caress those guys blocking js)
|
# ? Nov 25, 2014 16:56 |
|
I think it's actually possible to reconcile the idea of supporting nojs (especially for 3G where the js may take a while to come down the line) while still developing modern. That said, it involves bringing in Node to do essentially all your template rendering. If your primary back end framework has 'localhost' access to a Node server with a JSON API for spitting out template renders, potentially you can share all that code and give nojs something at least to look at on initial load. This is especially possible with React, which is pretty much idempotent if used correctly.
|
# ? Nov 27, 2014 16:06 |
|
Maluco Marinero posted:I think it's actually possible to reconcile the idea of supporting nojs (especially for 3G where the js may take a while to come down the line) while still developing modern. That said, it involves bringing in Node to do essentially all your template rendering. If your primary back end framework has 'localhost' access to a Node server with a JSON API for spitting out template renders, potentially you can share all that code and give nojs something at least to look at on initial load. Yeah, I actually started doing exactly this, but then realized that I just didn't care enough to go through the effort. If your content should be search engine indexable, you've got to do some work on this as well...
|
# ? Nov 27, 2014 16:55 |
No Wave posted:I think you're definitely right. Do you still feel like you're getting enough out of Django, or have you been tempted to use a different framework? Another thing Django has going for it is the huge community around it. There are a TON of things you can drop into Django and they 'just work' with minimal configuration.
|
|
# ? Nov 28, 2014 07:27 |
|
fletcher posted:Another thing Django has going for it is the huge community around it. There are a TON of things you can drop into Django and they 'just work' with minimal configuration. What we need is a narrated version of that site.
|
# ? Nov 28, 2014 09:42 |
|
Hey! I'm having trouble reaching static content (css, js, etc). My app is called 'website'. In settings.py I have STATIC_URL = '/static/' which works in the development server, but not nginx. This is a stock digitalocean ubuntu 14.04 django 1.7.1 one-click setup. I'm getting a 404 when I point my browser to blah.com/static/hello.css, with or without the following alias in /etc/nginx/sites-enabled/django: pre:location /static { alias /home/django/django_project/website/static; } Edit: That's odd. I looked in /var/log/nginx/error.log and I'm getting: pre:2014/12/04 16:33:15 [error] 1051#0: *242 open() "/home/django/django_project/django_project/static/css/hello.css" failed (2: No such file or directory) Edit 2: Despite restarting guni-- AH poo poo I needed to restart nginx too. Nevermind. epswing fucked around with this message at 23:22 on Dec 4, 2014 |
# ? Dec 4, 2014 22:21 |
|
Can you paste your whole server block? There could be other matchings going on. Can you set only the static location block on and put autoindex on and browse the directory? Nginx normally runs as nobody but the files need to be readable by a set user (default www-data) in order for the web server to see them. I didn't think an error there was a 404 though.
|
# ? Dec 4, 2014 22:47 |
|
Hey django-rest-framework folks. For one of my serializers I'm returning a queryset of users but I want to restrict that to only non-staff users. Is there a way to filter the queryset that the serializer returns?
|
# ? Dec 10, 2014 01:03 |
|
|
# ? May 16, 2024 18:48 |
Blinkz0rz posted:Hey django-rest-framework folks. For one of my serializers I'm returning a queryset of users but I want to restrict that to only non-staff users. Is there a way to filter the queryset that the serializer returns? Yup super easy to do, check out the get_queryset or queryset stuff on the Viewsets page.
|
|
# ? Dec 10, 2014 01:13 |