Flask-AppBuilder ModelView and ChartView in same page - flask

Is it possible to make a page in flask appbuilder that has both a ChartView and a FormView

Related

How to disable header " X-Frame-Options: deny "?

I created a website in Django that I deployed on heroku. I am trying to display this website from an html page using an iframe. However, when I load my html page, I get the error: gkwhelps.herokuapp.com refused the connection. And when inspecting the page I get the following message:Refused to display 'http://gkwhelps.herokuapp.com/' in a frame because it set 'X-Frame-Options' to 'deny'. To solve this problem, I modified my settings.py like this:
MIDDLEWARE = [
...
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
from django.http import HttpResponse
from django.views.decorators.clickjacking import xframe_options_exempt
#xframe_options_exempt
def ok_to_load_in_a_frame(request):
return HttpResponse("This page is safe to load in a frame on any site.")
and I updated my site. But despite this, I still get the same error when I reload my page. I don't know why yet I updated my site.
You can try the following for setting same origin xframe option
from django.views.decorators.clickjacking import xframe_options_sameorigin
#xframe_options_sameorigin
def ok_to_load_in_a_frame(request):
return HttpResponse("This page is safe to load in a frame on any site.")
If you want to set it for your whole app, you could try adding the below line in your settings.py file
X_FRAME_OPTIONS = 'SAMEORIGIN'

How to properly use django-cms apphooks

Below is my django cms apphook, its showing the app on the drop down but it doesn't hook the application to a page.
The project is in django 2.1.11, python3.7.1, and django cms 3.6.0
I have tried to change the apphook file to cms_apps.py and cms_app.py. I have also tried this tutorial.
I would be happy if someone can share a working manual for this procedure.
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
#apphook_pool.register # register the application
class PeoplemanagerApphook(CMSApp):
app_name = "peoplemanager"
name = "People Application"
def get_urls(self, page=None, language=None, **kwargs):
return ["peoplemanager.urls"]
The page loads, however it does not display the contents of the model

How to set image from external server to kv file

My code works perfectly for image saved in same directory.
#!/usr/bin/kivy
import kivy
kivy.require('1.7.2')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
Builder.load_string('''
<MenuScreen>:
GridLayout:
cols: 1
Button:
on_press: root.val1()
Image:
source: "myimage.PNG"
size: self.parent.width, self.parent.height
allow_stretch: True
keep_ratio: False
''')
class MenuScreen(Screen):
def val1(self):
print "i am executed"
sm = ScreenManager()
menu = MenuScreen(name='menu')
sm.add_widget(menu)
class MainApp(App):
def build(self):
return sm
if __name__ == '__main__':
MainApp().run()
What changes should be made in this code if i want to take image from external source ie
Image:
source: "http://example.com/myimage.jpg"
Obviously this does not work. Please help.
Try using AsyncImage instead. From the documentation:
To load an image asynchronously (for example from an external
webserver), use the AsyncImage subclass:
aimg = AsyncImage(source='http://mywebsite.com/logo.png')
This can be useful as it prevents your application from waiting until
the image is loaded. If you want to display large images or retrieve
them from URL’s, using AsyncImage will allow these resources to be
retrieved on a background thread without blocking your application.

Django: Views problem with Django + django-registration + jinja

So, I have a django project that is using jinja2 rendering, and I also installed django-registration to make my life easier. I ran into the following problem:
Going to homepage I render it with jinja. In order to check for authentication, I have to use jinja's syntax, which is user.is_authenticated(). However, in regular django templating, this check is done with user.is_authenticated. If in regular django templating there are (), it gives error.
So going to the /accounts/login/ page, the django-registration modul doesn't do anything special, so it forwards the url to the standard django views the following way:
from django.contrib.auth import views as auth_views
url(r'^login/$',
auth_views.login,
{'template_name': 'registration/login.html'},
name='auth_login'),
So I know for sure I shouldn't be changing the django.contrib.auth view, but then where do i put my own view? In myapp/views.py?
And also, do I have to copy paste the django view, and then modify on top of it (in this case simply replace the render with render_jinja) or is there a way to 'extend' this original django view to my own slightly modified view for logging in?
Whether right or wrong, in the registration module, I made a new view, that handled the logging, copying a few lines from here and there. It logical and seems to be working fine.

Is it possible to include a custom 404 view for a Django app without changing anything at the project level?

I'm creating a Django app and trying to have it touch the containing project in as few places as possible.
I've created a custom 404 view which works as expected but only when I add handler404 to the project-level urls.py.
I want the custom 404 view that I've written to apply to this particular app only, but from the information I've come across it appears that this may not be possible. Adding handler404 to the app-level urls.py does not have any effect.
Does Django support custom 404 views at the application level?
Instead of finishing your view with:
return render_to_response(...)
Get the response object and check its status:
out = render_to_response(...)
if out.status_code==404:
# redirect to your 404 page
else:
return out