django html5 cache in django 1.7 - django

I've got some problems implementing 3rd party django package django-html5-appcache.
Documentation especify that migrate command must be executed, but when i execute command:
python manage.py migrate html5_appcache
Outputs:
"No migrations to apply"
However I decided to complete installation steps. but testing it maniffest file appears to be empty (according to docs, urls suppose to autodiscover):
CACHE MANIFEST
# version: $0$
# date: $-$
NETWORK:
*
And Chrome Console Outputs:
Creating Application Cache with manifest http://127.0.0.1:8000/manifest.appcache
127.0.0.1/:1 Application Cache Checking event
127.0.0.1/:1 Application Cache Downloading event
127.0.0.1/:1 Application Cache Progress event (0 of 0)
127.0.0.1/:1 Application Cache Cached event
Im using Django 1.7
Any body has expirience with this django package?

I suspect that you're supposed to put the following code in your urls.py to get autodiscover.
Enable appcache discovery by adding the lines below in urls.py:
import html5_appcache
html5_appcache.autodiscover()
(Source: documentation here: https://django-html5-appcache.readthedocs.org/en/latest/installation.html)
Also, python manage.py migrate commands are used to alter the DB structure and should not affect your urls.py.

Related

sentry Does not work when i deploy project on the server

I have a Django project with sentry configurations.
when i run project in my local, i can see errors in my sentry panel, but when i push the project on server and run it, i cant see the errors in sentry panel.
This is my config code
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration
sentry_sdk.init(
dsn="https://********#****.ingest.sentry.io/*****",
integrations=[DjangoIntegration(), CeleryIntegration()],
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True
)
I also dockerized the project, and I had a problem with Gunicorn that I was able to fix, but it still sentry doesn't work when I run the project on the server.
In some cases people says that setting sentry parameters send_default_pii=False helps or debug=True
I have similar issue, Sentry works when uwsgi started by hand but does not work when process started by Fabric.

Running into a booting worker issue with Django application when deploying to heroku [duplicate]

I built a Django 1.9 project locally with sqlite3 as my default database. I have an application named Download which defines the DownloadedSongs table in models.py:
models.py
from __future__ import unicode_literals
from django.db import models
class DownloadedSongs(models.Model):
song_name = models.CharField(max_length = 255)
song_artist = models.CharField(max_length = 255)
def __str__(self):
return self.song_name + ' - ' + self.song_artist
Now, in order to deploy my local project to Heroku, I added the following lines at the bottom of my settings.py file:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
My application has a form with a couple of text fields, and on submitting that form, the data gets inserted into the DownloadedSongs table. Now, when I deployed my project on Heroku and tried submitting this form, I got the following error:
Exception Type: ProgrammingError at /download/
Exception Value: relation "Download_downloadedsongs" does not exist
LINE 1: INSERT INTO "Download_downloadedsongs" ("song_name", "song_a...
This is how my requirements.txt file looks like:
beautifulsoup4==4.4.1
cssselect==0.9.1
dj-database-url==0.4.1
dj-static==0.0.6
Django==1.9
django-toolbelt==0.0.1
gunicorn==19.6.0
lxml==3.6.0
psycopg2==2.6.1
requests==2.10.0
static3==0.7.0
Also, I did try to run the following commands as well:
heroku run python manage.py makemigrations
heroku run python manage.py migrate
However, the issue still persists. What seems to be wrong here?
Make sure your local migration folder and content is under git version control.
If not, add, commit & push them as follows (assuming you have a migrations folder under <myapp>, and your git remote is called 'heroku'):
git add <myapp>/migrations/*
git commit -m "Fix Heroku deployment"
git push heroku
Wait until the push is successful and you get the local prompt back.
Then log in to heroku and there execute migrate.
To do this in one execution environment, do not launch these as individual heroku commands, but launch a bash shell and execute both commands in there: (do not type the '~$', this represents the Heroku prompt)
heroku run bash
~$ ./manage.py migrate
~$ exit
You must not run makemigrations via heroku run. You must run it locally, and commit the result to git. Then you can deploy that code and run those generated migrations via heroku run python manage.py migrate.
The reason is that heroku run spins up a new dyno each time, with a new filesystem, so any migrations generated in the first command are lost by the time the second command runs. But in any case, migrations are part of your code, and must be in version control.
As Heroku's dynos don't have a filesystem that persists across deploys, a file-based database like SQLite3 isn't going to be suitable. It's a great DB for development/quick prototypes, though. https://stackoverflow.com/a/31395988/784648
So between deploys your entire SQLite database is going to be wiped, you should move onto a dedicated database when you deploy to heroku I think. I know heroku has a free tier for postgres databases which I'd recommend if you just want to test deployment to heroku.
python manage.py makemigrations
python manage.py migrate
python manage.py migrate --run-syncdb
this worked for me.
I know this is old, but I had this issue and found this thread useful.
To sum up, the error can also appear when executing the migrations (which is supposed to create the needed relations in the DB), because recent versions of Django check your urls.py before doing the migrations. In my case - and in many others' it seems, loading urls.py meant loading the views, and some views were class-based and had an attribute defined through get_object_or_404:
class CustomView(ParentCustomView):
phase = get_object_or_404(Phase, code='C')
This is what was evaluated before the migrations actually ran, and caused the error. I fixed it by turning my view's attribute as a property:
class CustomView(ParentCustomView):
#property
def phase(self):
return get_object_or_404(Phase, code='C')
You'll know quite easily if this is the problem you are encountering, as the Traceback will point you towards the problematic view.
Also this problem might not appear in development because you have migrated before creating the view.

API is not working in flutter_web(Enabled CORS)

I Made one POST API in Django rest framework. It working perfectly in Postman in also chrome and other browsers but it is not working in my flutter_web project. it is giving me XMLHttpRequest error. for enable CORS I had used python -m pip install django-cors-headers.
you can check my api from https://findweight.herokuapp.com/idealweight which takes raw data for example 5.
you can check my whole error from following image:- https://i.stack.imgur.com/Fx8Xp.png
Make sure that you have applied all the migrations properly on the backend.
If not then migrate it first by python manage.py migrate.
And restart your server again and see the logs by changing DEBUG = True,
So you can see what is the error (NOTE: Make sure you change DEBUG = False before going to production).
And also, check if you have set up CORS property properly on the backend.

What is an efficient way to develop Airflow plugins? (without restarting the webserver for each change)

I am looking for an efficient way to develop plugins within Airflow.
Current behavior: I change something in Python files e.g. test_plugin.py, reload the page in browser and nothing happens until I restart the webserver. This is most annoying and time consuming.
Desired behavior: I change something in Python files and the change is reflected after reloading the app in the browser.
As Airflow is based on Flask and in Flask the desired behavior is achievable by running Flask in debug mode (export FLASK_DEBUG=1, then start Flask app): Can I achieve the Flask behavior somehow in Airflow?
It turns out that this was indeed a bug with the Airflow CLI's webserver --debug mode; future versions will have the expected behavior.
Issue: https://issues.apache.org/jira/browse/AIRFLOW-5867
PR: https://github.com/apache/airflow/pull/6517
In order to run Airflow with live reloading, run the following command (10.7+):
$ airflow webserver --debug
In contrast to the code modification suggested by #herrjeh42, make sure that your configuration does not include unit_test_mode = True in order to enable reloading.
Cheers!
You can force reloading the python code by starting the airflow webserver in debug & reload mode. As of Airflow 1.10.5 I had to modify airflow/bin/cli.py (from my opinion the line is buggy).
old:
app.run(debug=True, use_reloader=False if app.config['TESTING'] else True,
new:
app.run(debug=True, use_reloader=True if json.loads(app.config['TESTING'].lower()) else False,
Change in airflow.cfg
unit_test_mode = True
Start the webserver with
airflow webserver -d

Google App Engine - This app has no instances deployed

App Instances:
App Versions:
app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /my_uri
script: path.to.my.script.script.app
I created a Python Flask app with Google App Engine. I initially ran into some issues, so I re-deployed the app. This created a new version. After doing so, I deleted the previously existing version which had one instance deployed. The currently deployed version has no instances deployed, as you can see in the image at the link above.
When I submit a request to my-app-ID.appspot.com/my_uri, I get a 404 error:
Error: Not Found
The requested URL /my_uri was not found on this server.
I believe this is related to my app not having an instance deployed. Is that correct? If so, how would I remedy this?
If not, what could be causing the 404 issue?
Thanks everyone!
As your error message indicates gcloud app browse makes a request for the / url to your app.
From Request handlers:
When App Engine receives a web request for your application, it calls
the handler script that corresponds to the URL, as described in the
application's [app.yaml][2] configuration file . The Python 2.7
runtime supports the WSGI standard and the CGI standard for
backwards compatibility. WSGI is preferred, and some features of
Python 2.7 do not work without it. The configuration of your
application's script handlers determines whether a request is
handled using WSGI or CGI.
But your app.yaml file does not contain a handler with a matching url pattern (as / doesn't match /my_uri), so GAE doesn't know which app script to launch for that request, so it'll return 404.
So the first thing you have to do is to add in app.yaml a handler with a url pattern that matches a / request.
You may want to go through the Getting Started with Flask on App Engine Standard Environment guide. In there the recommended handler would be:
handlers:
- url: /.*
script: main.app
The above alone won't necessarily make your app work, there's plenty of other things that can go wrong. You should get familiar with the app's log viewer as that's essential for debugging your app. See Understanding request log fields
But before you even go to deployment on GAE, learn how to run and test your app locally. See Using the Local Development Server