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.
Related
After modified inspectdb, I want to run it when index page on web is loaded. So, in my view.py - def index, I´m trying to do the next:
def index(request):
subprocess.Popen("rm /path/app/models.py", shell=True)
subprocess.Popen("python2.7 /path/manage.py inspectdb_New > /path/app/models.py", shell=True)
return render_to_response('index/index.html', context_instance = RequestContext(request))
That is not working. I tried with os.system, subprocess.call as well, but it´s still not working.
For me, at least, looks like I can´t modify models.py in execution time but I don´t know what could be the problem...
Any idea guys?
Thanks.
You can't change your models.py while the webserver is running, because models (and other python code) are only loaded at server startup.
There are 2 parts in you question:
a) you want the shell to do something when view function is called. I have alarm beeping already.
b) you want to load new model. It won't gonna happen. You must reload to have new code loaded in (model introspected, etc.). Probably you use runserver command, take a look on Django autoreloader code: https://github.com/django/django/blob/master/django/utils/autoreload.py
It tracks files listed by gen_filenames() and reload when something was changed. You model was not listed so the change to the code will not be reflected.
I would touch something or remove .pyc files to force the reloader.
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 am using django.views.i18n.set_language() redirect view and HTML form where user can choose language.
I am doing everything as it's described in Django documentation for i18n translation .
The only difference that I made is that within HTML form I changed value of next parameter from {{redirect_to}} to {{request.get_full_path}}
Anyway, It worked completely fine while I was testing it locally. I could select different language and it would reload current page but with different language.
Now I put application on VPS where I use Gunicorn as application server and Nginx as web server. Now when I select different language it still changes it but it always redirect me to to home page / (site root).
I have no idea why is that happening now and how to change it. I want that he reloads the same page again instead of redirecting me to the / always. Anyway, at translation still works fine.
Thank you for your replys
Kind regards
Wander Nauta answered it in the comments
Are you sure request.get_full_path is available in the template?
You need to add django.core.context_processors.request in your template context processors settings, which is not there by default.
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!
Using the development server, it works with debug=True or False.
In production, everything works if debug=True, but if debug=False, I get a 500 error and the apache logs end with an import error: "ImportError: cannot import name Project".
Nothing in the import does anything conditional on debug - the only code that does is whether the development server should serve static files or not (in production, apache should handle this - and this is tested separately and works fine).
Just to say, I ran into a similar error today and it's because Django 1.5 requires the ALLOWED_HOSTS parameter in the settings.
You simply need to place this row to make it work ;)
...
ALLOWED_HOSTS = '*'
...
However, be aware that you need to set this parameter properly according to your actual host(s) (https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts)!
Values in this list can be fully qualified names (e.g. 'www.example.com'), in which case they will be matched against the request’s Host header exactly (case-insensitive, not including port). A value beginning with a period can be used as a subdomain wildcard: '.example.com' will match example.com, www.example.com, and any other subdomain of example.com. A value of '*' will match anything; in this case you are responsible to provide your own validation of the Host header (perhaps in a middleware; if so this middleware must be listed first in MIDDLEWARE_CLASSES).
So basically it's better for you to use this type of configuration once you're in production:
...
ALLOWED_HOSTS = [
'.yourdomain.com',
]
...
thanks to gertvdijk for pointing this out
This happens if you have a circular import in one of your files. Check and see if you are importing something from Project and then importing something in Project from the original file that originally imported Project.
I ran into this same problem recently, and rearranging some of my imports helped fix the problem.
This can also happen if you do not have both a 500.html and 404.html template present. Just the 500 isn't good enough, even for URIs that won't produce a 404!
I had this problem as well. Although it persisted even when setting Allowed_hosts and already having 404 and 500 templates.
I also checked for circular imports, but that was not it.
I finally had django produce a log file, https://stackoverflow.com/a/15100463/1577916
I accidentally left in a "get_host" function which now exists under
HttpRequest (changed to HttpRequest.get_host())with Django 1.5.
for some reason that was not raising an error with Debug True OR False.