Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
CarForumPoster
Jun 26, 2013

⚡POWER⚡

Thermopyle posted:

Here's a neat thing I've been doing.

Using the inspect and ast modules along with django's checks framework to enforce some style and code stuff. Stolen from this guy.

Here's stuff he's enforcing:


We have some abstract model classes that require some configuration by the model that is implementing them. I'm writing some checks to make sure thats done correctly right now.

Could you explain this like I am 5? What problem does this solve?

Adbot
ADBOT LOVES YOU

CarForumPoster
Jun 26, 2013

⚡POWER⚡
Any tips for hiring someone to develop a Django based site when I personally don’t know much about django and am just becoming handy in Python?

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I wanna start baby’s first Django project this week, basically displaying a subset of a pandas dataframe in a bootstrap table based on url strings.

I picked out a bootstrap theme I like.

I watched sentdex’s Django tutorials and it seems pretty doable. Copy paste some static stuff, add some jinja things, seems easy enough.

What are packages like this for? Would it make getting started easier?
https://pypi.org/project/django-bootstrap4/

My current website is with weebly and I’m thinking about redoing it. It’d be nice if my nontechnical cofounder can make minor edits with a WYSIWYG editor. Should I got for djangoCMS?

Is this useful: https://github.com/divio/djangocms-bootstrap4

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I think it was in this thread that someone had an issue with their site loading already "pre scrolled down" or in the middle of the page. I'm having the same issue, does this ring a bell to anyone?

CarForumPoster
Jun 26, 2013

⚡POWER⚡

KICK BAMA KICK posted:

How many more times am I gonna be trying to nest like three {% with some_str= [...] %} and a bunch of filters to get a template to display something formatted a certain way if a value exists but something else formatted different if it's not before I realize "just put a method on the model that handles it with a one-line f-string and call that from the template"?

I'm sure I'm just overlooking the right filters to more efficiently do what I want but I have a bad habit of trying to make like yesno and default_if_none handle situations more complex than they should.

f-strings are the best things

CarForumPoster
Jun 26, 2013

⚡POWER⚡
Why would anyone wanting a blog based website not use Wordpress? It has basically everything you need to get writing, SEO your site, etc. way

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I haven’t used them but zapier will let you do web sockets and it looks like it’s super easy. I was gonna give them a try for a mail tracking API I want to start using where the only way they’ll give you updates is a POST via websockets.

EDIT in my use case I’m just sticking them in an RDS database so I have some data about delivery times.

CarForumPoster fucked around with this message at 02:12 on Mar 28, 2020

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I'm trying to set up analytics tool Segment on a Django project. Once a user has logged in, I want to attribute them with their previous history.

The Segment Javascript that sits on my website seems to generate a user id, what I can't figure out is how to use the one it has created nor how to send it one so I can use the code shown in the docs (linked above) on login to identify them:
code:
analytics.identify('019mr8mf4r', {
    'email': 'john@example.com',
    'name': 'John Smith',
    'friends': 30
})
EDIT: I'm super dumb and just templated it in to the javascript in my base html file.

CarForumPoster fucked around with this message at 18:52 on May 19, 2020

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I need to make user logins for a Django site where I snail mail the usernames and passwords to people and I can't figure out how to externally check if a user exists or create a new user from a python script.

Whats a decent way to create new usernames and passwords externally from a django site using a python script?

The site hosted on AWS ElasticBeanstalk w/ an RDS database.

EDIT: Should I just write a script to SSH into my instance and then try it via the django shell? Is there a recommended SSH via python library? I see a few different ones all looking pretty dated.

CarForumPoster fucked around with this message at 19:21 on Jun 5, 2020

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Data Graham posted:

Really what's wrong with just adding users through the admin?

How automated does it need to be?

My sales enrichment team is using an enrichment web app I made to create 5000+ users/year. I want to make a button for them to generate the creds but it complicated the explanation.

IAmKale posted:

What if you create a new API endpoint to a custom view that you POST a username + password to? It'd attempt to create the user account, or could return a 400 if an account with that username already exists.

If you secure it with token auth (via, say, Django Rest Framework), you can expose the new endpoint to the public while ensuring that only you can interact with it.

This sounds exactly like what I want but I've not tried something like this before. Looking to spend max 2-3 days on it.

EDIT: https://medium.com/swlh/build-your-first-rest-api-with-django-rest-framework-e394e39a482c

This looks pretty easy actually, Ill give it a try early next week

CarForumPoster fucked around with this message at 20:46 on Jun 5, 2020

CarForumPoster
Jun 26, 2013

⚡POWER⚡

IAmKale posted:

What if you create a new API endpoint to a custom view that you POST a username + password to? It'd attempt to create the user account, or could return a 400 if an account with that username already exists.

If you secure it with token auth (via, say, Django Rest Framework), you can expose the new endpoint to the public while ensuring that only you can interact with it.

So using the DRF looks like the winning option and looks pretty easy. I got it up and running pretty fast, got an API token, etc. When I changed from listing all data about all users to trying to return the data for specifically the logged in user I now get the below error:

code:
TypeError at /api/[endpoint]/

'User' object is not iterable

Django/Python Version: 1.11.24/3.7.4
in views.py
code:
class CaseViewSet(viewsets.ModelViewSet):
    permission_classes = (IsAdminUser,)
    # queryset = Case.objects.all()
    serializer_class = CaseSerializer
    def get_queryset(self):
        return Case.objects.filter(self.request.user)
If I try to get just the current users object with that function, I get the error. If I make my queryset var all "Case" objects, works as expected. (i.e. uncommenting the line and commenting out the function. makes it work) There should only be one User per Case

Any help? I don't see how I'm trying to iterate over User there.

CarForumPoster fucked around with this message at 15:30 on Jun 9, 2020

CarForumPoster
Jun 26, 2013

⚡POWER⚡

NtotheTC posted:

objects.filter expects keyword arguments that it tries to iterate over: filter(blah=self.request.user) where blah is the name of the foreign key field for user on your Case model

Man I'm dumb. Fixed, thank you!

CarForumPoster
Jun 26, 2013

⚡POWER⚡

minato posted:

I have what I think is a common problem, but I can't seem to find a solution.

I want to show 2 form fields where the first decides whether the 2nd is displayed. e.g.

code:

Field 1: (Radio buttons)
( ) Foo
( ) Bar
( ) Baz

Field 2: (only visible if "Baz" is selected)
[ <some CharField> ]
The standard solution is to use Javascript to show/hide Field 2 when "Baz" is selected/de-selected. But this seems fragile, because now I have to write JS code in the template that's tightly-coupled to the Form definition but yet is in a different file. And if someone renames "Baz" or adds a new item to Field 1, it might break that JS code. Without comprehensive tests, it's going to be easy to break this code.

I have many forms like this so I'd like a generic way to solve it. What I'd like to do is programmatically define the relationship between the Field 1 & 2 in the Form definition, and have some general-purpose JS parse that relationship and handle the client-side show/hiding. It feels like this problem is common enough that someone must have solved it, but I can't seem to find any libraries that would assist here. Any ideas?

I’m a Django newbie but this is trivially easy in Dash (Flask) with callbacks.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Hadlock posted:

What's the go to Django plugin for payment processing for an American centric ecommerce website these days

Any third party payment processor seems to have a Django version

I easily found one for square, stripe and PayPal

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I see tons of django projects with the secret key in the public repo. How much of a security risk is that? Everywhere I read says its a critical one but I dont understand why. What can someone actually do with a secret key? I read its the seed for the hash for the passwords...I take it if someone gets DB access they can then be decrypted or ...un...salted?

CarForumPoster
Jun 26, 2013

⚡POWER⚡
I’ve used Django CMS twice now but not for any good reason over wagtail or mezzanine. Any opinions amongst goons as to one being way better? With CMS I basically install and forget.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Hed posted:

Does anyone here run Django serverless (Lambda, Azure Functions) in production? I have a couple of Zappa sites that are basically landing pages but for anything more involved I still host Django on EC2, with an RDS database if the site is sufficiently complex.

With Zapppa looking unhealthy I was curious if anyone is looking at anything else like serverless framework or if it's just not a great fit for Django.

For a more involved site with lots of async task queues spinning off work I'm looking for recommendations of what people like between moving to something like ECS, or going full bore with lambdas calling lambdas, etc.

I don’t have any complicated ones but yea deployed with Zappa is the easiest route. AWS SAM is good too.

For anything with a series of lambdas calling lambdas I use lambda+ stepfunctions deployed with SAM.

Adbot
ADBOT LOVES YOU

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Hed posted:

If anyone cares I solved this by writing some Django middleware, and putting it higher in the settings.MIDDLEWARE stack than the built-in SecurityMiddleware, such that it short-circuits the response before "Host:" header gets checked in the HTTP request:

Python code:
class HealthCheckMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.
        self.healthy_response = HttpResponse("OK")

    def __call__(self, request: HttpRequest):
        # Code to be executed for each request before
        # the view (and later middleware) are called.
        if request.META["PATH_INFO"] == "/healthcheck/":
            return self.healthy_response
        else:
            response = self.get_response(request)
            return response


This actually is helpful, I forgot that we had this same problem 2 years ago and had to fix it until you posted your solution, unfortunately. I still don't recall how we fixed it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply