I've been having trouble with my templates not updating in the Google App Engine Dev Python Server. If I leave the server running for a while, my templates will not update in the browser after I change them. My best guess is that jinja2 is caching these templates some how?
I'm rendering my templates using the following code:
_jinja_environment = jinja2.Environment(
loader = jinja2.FileSystemLoader(root_dir))
def write_template(self, template_name, template_data = {}):
template = _jinja_environment.get_template(template_name)
self.response.out.write(template.render(template_data))
I've tried restarting my app engine application, as well as undeploying and re-deploying, but the templates still don't update.
Anyone got any ideas?
Did you try any of the following
Clearing browser cache,
Renaming the template dir,
Changing the version
It none of them could fix it, then I dont know what is causing the problem.
This one is a similar question although the trouble happened after deploying.
Try the following:
Go to the admin console. On local machine it's: "http://localhost:8080/_ah/admin/datastore"
select the appropriate entity kind and then click on List Entities
click on Flush Memcache
Then try reloading the app.
I just experienced the same issue. I have one .py file and one .html file. I tried to edit a textarea to output some text in it, but it wasn't refreshed in the browser correctly. Still the old HTML file was displayed. After I restarted the app engine it worked just fine.
So I did it again and still the same problem. But if you edit the .py file and save it, the HTML file is reloaded into app engine. I don't know why, but I think deleting a character and undo it + save is faster than always restarting the whole app.
Maybe it helps!
Related
I'm using gunicorn and nginx to serve a flask application, my website has a blogging feature where users can write blogs, once they do, their input is saved as an html file (I use tinyMCE to generate it) and a flask view is added to a views.py file. Now, in deployment, I just used
use_reloader=True
This ensured that every time a new file was added, it was detected, now in production, I don't know how to implement it, gunicorn has --reload option but the docs say that it's only for development. Can someone please provide an insight on how to implement this feature? Thanks!
You don't need a new view for every html file. You could use a generic view that renders the appropriate html according to the url requested.
I am facing a very strange problem. I have a Django project which runs fine in four environments (development, testing, staging and production), besides one strange bug.
In the production environment, the change form for a single model isn't rendered anymore. The rendered html page only contains the csrf token and then the submit buttons. All other change forms for other models are rendered just fine.
The result looks like this:
I am running the same code based (same commit and branch) on an identical staging server, and everything looks fine.
What could cause the faulty rendering of the form? How can I further debug it?
This is what I tried so far:
I switched back to a commit where I was absolutely sure that the admin change form worked. Form still not rendered.
I compared the pip packages between the Staging and Production. Both are identical (Django 1.7.1)
I checked the log files on the dev server. No Django error found.
I am running out of ideas how to debug this issue. Any suggestions?
Update March 23rd
It turns out that setting DEBUG=True, let's Django rendering the form. If DEBUG=True, the form rendering is failing silently. Why is that?
idea 1:DEBUG=False- static files are not handled by django but nginx /apache does
idea 2:Compare settings.py and url.py (mostly there r changes between staging/prod env's)
idea 3:For debugging run django stand-alone (runserver) without apache/fcgi
I've got a Django app running on localhost:80, and another app running on localhost:41984. Now, in the app, I'm trying to hook things up so that hitting localhost/view/41984 redirects to localhost:41984, without changing the URL in the browser: effectively, URL masking of sorts.
Could someone give me some pointers on achieving this? Django's HttpResponseRedirect does the redirection, but the URL changes too, which isn't what I want. I read somewhere that people do this with .htaccess, but I'm not planning on using Apache.
Thanks!
The best option should be, to run both app in the same server. Just add one to the INSTALLED_APPS list.
Then, you can do:
return redirect('some-view-name', foo='bar')
The view name is the one you define in the urls.py file:
url(r'^enter/$', 'yourApp.views.viewName', name='some-view-name'),
For more info https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect
If you need to run booth app in differents servers... I would say that you need a REAL web server, apache, ngix... what you want, but no ./manage.py runserver
First, let me say I'm new to Django and I'm still learning the ropes.
I recently installed the django-registration package. Everything works fine except for one small glitch with logins/authentication. /accounts/login works fine and user.authenticated is fine. Within my app directory/folder is where the problem is. I can't seem to call user.authenticated, it always return False. But outside this app directory everything is fine.
I can even do /users/()
What am I missing? Should I add anything to settings.py?
Thanks.
UPDATE
Thanks people for your comments. Here is it, I have a base.html file when I check localhost/accounts/login - I can see that the user.authenticated function works fine, it doesn't return false, this is after a successful login. If I check the root of the main app on localhost nothing user.authenticated always return false.
I am using Django to develop an API using an algorithm I wrote.
When someone requests a url, my urls.py calls a function in views.py which serves
page that returns a JSON string.
If my algorithm is in my views.py file, or in another file on my server, would it be possible for a user to view the contents of this file, and then see my algorithm?
In other words, when using Django, which files will never be served to a user, and which files will be?
Is there any way I can stop someone from viewing my algorithm if it's in a .py file? Other than Chmodding the file or encrypting the code?
Thank you for your time.
Django only serves the responses that you explicitly create and return from your views. There is no general ability to request files from it.
Make sure your source code isn't in a directory that your web server is configured to serve from, and make sure your settings.py value for DEBUG is False, and you should be fine. Oh, and just in case - don't try to use the Django development server in production.
As long as nobody has shell access to your server, people will never see more than the actual HTML output of your page. .py files are not shown to the user that has requested an url in the browser.