Flask css not updating [closed]

Problem is, as already said, related to browser cache. To solve that, you could add some dynamic variable to your static (css, js) links. I prefer last modified timestamp for each file. /static/css/style.css?q=1280549780 Here is a snippet for that: http://flask.pocoo.org/snippets/40/ @app.context_processor def override_url_for(): return dict(url_for=dated_url_for) def dated_url_for(endpoint, **values): if endpoint == ‘static’: filename = values.get(‘filename’, …

Read more

Set LD_LIBRARY_PATH before importing in python

UPDATE: see the EDIT below. I would use: import os os.environ[‘LD_LIBRARY_PATH’] = os.getcwd() # or whatever path you want This sets the LD_LIBRARY_PATH environment variable for the duration/lifetime of the execution of the current process only. EDIT: it looks like this needs to be set before starting Python: Changing LD_LIBRARY_PATH at runtime for ctypes So …

Read more

How does Python’s “super” do the right thing?

Change your code to this and I think it’ll explain things (presumably super is looking at where, say, B is in the __mro__?): class A(object): def __init__(self): print “A init” print self.__class__.__mro__ class B(A): def __init__(self): print “B init” print self.__class__.__mro__ super(B, self).__init__() class C(A): def __init__(self): print “C init” print self.__class__.__mro__ super(C, self).__init__() class …

Read more

Python Requests: Post JSON and file in single request

See this thread How to send JSON as part of multipart POST-request Do not set the Content-type header yourself, leave that to pyrequests to generate def send_request(): payload = {“param_1”: “value_1”, “param_2”: “value_2”} files = { ‘json’: (None, json.dumps(payload), ‘application/json’), ‘file’: (os.path.basename(file), open(file, ‘rb’), ‘application/octet-stream’) } r = requests.post(url, files=files) print(r.content)

How do I document a constructor for a class using Python dataclasses?

The napoleon-style docstrings as they are described in the sphinx docs (see the ExampleError class for their take on it) explicitly touch on your case: The __init__ method may be documented in either the class level docstring, or as a docstring on the __init__ method itself. And if you do not want this behavior, you …

Read more

How to provide additional initialization for a subclass of namedtuple?

edit for 2017: turns out namedtuple isn’t a great idea. attrs is the modern alternative. class Edge(EdgeBase): def __new__(cls, left, right): self = super(Edge, cls).__new__(cls, left, right) self._hash = hash(self.left) * hash(self.right) return self def __hash__(self): return self._hash __new__ is what you want to call here because tuples are immutable. Immutable objects are created in …

Read more