django same localhost not responding in another browser or second instance - django

my new created django project working fine with this information
Django version 2.1.7, using settings 'django_server_api.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
running fine
then i opened in one browser is loaded quickly working quickly.
but if i open same local host in another browser it is taking more than 5 minutes, i dont know what is the issues? may be django is like this? or do i need to change any config in the setting,py file ?

Some browsers (Firefox) has a problem browsing to localhost on some Windows machines.
You can solve it by switching off ipv6, which isn't really recommended.
Using 127.0.0.1 directly is another way round the problem.
Note : If there are heavy media is can also slow downs django

Related

Django - Server only works in one browser until I restart it

I have a Django project (it's a big project meanwhile) and I can only connect to it via localhost using one browser (Chrome, Opera, Firefox, it doesn't matter which browser I use). When I connect to it once, Django is "locked" in this browser. When I try to connect to Django using another browser, it gets timed out. When I restart it I can again choice which browser I would like to use. But then Django gets "locked" again in this browser.
Example:
Django Server starts; I use Chrome; I can't use Opera, Firefox or any other browser anymore.
Django Server restarts; I use Opera; I can't use Chrome, Firefox or any other browser anymore.
I know this isn't a question about code but I don't know where this question fits except for Stackoverflow.
Do you have any idea?
EDIT
I also have this strange behaviour when I use incognito.
EDIT 2
I tried to reset the middlewares but that didn't change anything.

Chrome not connecting to network

I was wondering how I could let Chrome connect to my network. I am using a website called Codeanywhere.com and I was using a Django container. I used the built-in terminal and installed Python 3.4 and Django 10. I created a project and ran the server, and it said it had created one at this ip: http://127.0.0.1:8000/. However, whenever I try to access it, it the site can't be reached. If it helps, I am using a Chromebook Thinkpad, and it is a school computer. They do block things with Lightspeed Systems and they have a lot of blacklisting things going on. I am trying to learn Django for a project. Below is a screenshot of the screen when I try to access the server.
My screenshot of the error screen.
I can't embed my image yet, I don't have 10 reputation points :/ It's a link instead.
Mistake #1
The server isn't located on your local host, so you need to go to the provided server. for example, when I opened a project I got this instruction:
To access your application over HTTPS, make sure your application is running on port 3000 and use the following link:
https://mysite-{username}551936.codeanyapp.com
Mistake #2
you should run the server with a specified ip commend - and use 0.0.0.0:3000 instead of the usual localhost, like so:
python manage.py runserver 0.0.0.0:3000
In addition, I would reccomend you to read the "mysite Container" file which explains everything about the setup in detail.

django + IIS fastcgi, some problems

I've successfully managed to setup django + IIS with fastcgi using this guide: https://pypi.python.org/pypi/wfastcgi
I've came across some problems:
1. I can't find a way to see error log - the python traceback, in apache with wsgi the traceback can be found in error.log, how can the same be done with IIS?
I've noticed that once in a while, after the site is "inactive" (no connections for a while), the next first request will be very slow. I've found related questions like this:
IIS and ISAPI-WSGI = very slow
But the accepted answer isn't going to be very useful to me, since I need to run it on IIS. /
From https://pypi.python.org/pypi/wfastcgi#route-handlers:
1. your WSGI_LOG location needs to be writable by the user your site runs under (the application pool user), so check the file permissions.
2: what's your IIS version? A slow application start-up is normal, but starting from IIS 7.5 you can enable AlwaysRunning as the application pool Start Mode, so the application pool is automatically started after a shut down. Do check your Idl Time-out (minutes) and Idle Time-out Action settings as well.

Django runserver & Firefox - caching conflict with multiple local sites running separately on same port?

I'm working on several Django projects on my local machine, following a single page application architecture. To initiate the server, I have a couple copies of a script in my /bin folder containing
#!/bin/bash
python /path/to/app/manage.py runserver 8080
and have each script with the app name. This makes the application accessible via localhost:8080. In addition, I usually have the majority of my site CSS inside main.css
My issue is that I seem to be coming across a caching issue with Firefox, regardless of which application server is running. Sometimes a page will load with almost no CSS styling, but the jQuery UI elements will be initialized and I can interact somewhat with the application, although the functionality and styling is seriously broken. Refreshing the page shows no improvement, and no errors are shown in the console.
Clearing the cache and changing the port in the scrip seem to solve the issue, but it requires me to have bookmarks for each project, whereas it is pretty convenient to have a single localhost:8080 URL for all projects.
Has anyone come across this issue, and is there a solution other than clearing cache and changing ports?
This thread discusses methods to prevent client side caching of content served by the development server in Django:
Fighting client-side caching in Django
I prefer to simply disable caching in my browser though, seeing that I spend so much time on developing that I don't want to bother with the hassle of trying to prevent it in my own code.
A simple web search for "how to disable caching in firefox" came up with this:
http://support.mozilla.org/en-US/questions/764993
I'm pretty sure that searching for the same thing for different browsers will also give you expected results.
EDIT:
These guys also seem to go pretty in depth about how to prevent the caching of static files when using the Django development server.
Turn off caching of static files in Django development server
Just add something like this to /etc/hosts:
127.0.0.1 site1.dev
127.0.0.1 site2.dev
Visit site1.dev:8080, now site1 has its own cache and cookies (session) in the browser.

Django - distinguish development server (manage.py runserver) from the regular one (eg. Apache)

I need a way to distinguish development server in Django (run eg. by ./manage.py runserver 0.0.0.0:8000) from the one being run on Apache. In case of Apache I use WSGI daemon mode, but I would like to find some more reliable solution for detecting execution on Django's development server.
What I currently use is similar to:
wsgi_wrapper = request.META.get('wsgi.file_wrapper')
wsgi_wrapper_path = wsgi_wrapper.__module__ if wsgi_wrapper else None
which seemingly gives wsgi_wrapper_path storing:
"wsgiref.util" string when run on Django's built-in development server,
None when run on Apache / WSGI in daemon mode,
The problem here is I am not sure if I can rely on that check (eg. if the production/staging/development server or my localhost configuration changes). I was not able to find any documentation regarding that.
I need that check primarily because of one issue with Django's development server: it sets request's CONTENT_TYPE (request.META['CONTENT_TYPE']) to "text/plain" even if the HTTP request itself had no content type set (eg. it was a GET request).
Any ideas regarding Django's development server detection (or solving issue with incorrect request content type on it) will be appreciated. Thanks.
Ps. I am basically asking this question: How can I tell whether my Django application is running on development server or not? for Django 1.4, trying to determine the solution that will be reliable enough in case configuration changes.
As a principle - when using a Production and Dev servers, they should have different configs - it is most common that they will use different databases, different mail settings, etc.
So the best place to tell the kind of the server is the configuration. I can point to two most-used approaches:
Config file
then in settings.py just add:
server = config.get("SERVER_TYPE", "DEV")
and have SERVER_TYPE only in the config file on PRODUCTION
Environment
Set SERVER_TYPE as environment variable when running the web server. I.e. for Supervisord, running the webserver:
environment=SERVER_TYPE=PROD
or for Apache:
SetEnv SERVER_TYPE PROD
This way you will be sure that as long as you don't mix the config files, you will always get the real server type, no matter how you start the server.
At least that why config files are used for.