Serve React with Django Server - django

I am following this tutorial in order to serve React through Django server, but I only get a blank page when I access http://localhost:8000/admin, and I get the following errors on Django local server console:
[20/Jun/2020 17:05:08] "GET /admin HTTP/1.1" 200 2217
[20/Jun/2020 17:05:08] "GET /static/css/main.5f361e03.chunk.css HTTP/1.1" 404 1821
[20/Jun/2020 17:05:08] "GET /static/js/main.853c8ab9.chunk.js HTTP/1.1" 404 1815
[20/Jun/2020 17:05:08] "GET /static/js/2.6d20342a.chunk.js HTTP/1.1" 404 1806
[20/Jun/2020 17:05:08] "GET /static/js/2.6d20342a.chunk.js HTTP/1.1" 404 1806
[20/Jun/2020 17:05:08] "GET /static/js/main.853c8ab9.chunk.js HTTP/1.1" 404 1815
I made all, and only, the changes stated in the tutorial.
EDIT
I have managed to make http://localhost:8000/admin work. I just had to add a coma in TEMPLATES:
TEMPLATES = [
{
# ...
'DIRS': [
os.path.join(BASE_DIR, 'build'),
],
# ...
}
]
But I still get the same error with http://localhost:8000/.
Thanks for your help.

Related

Django bootstrap files missing when static changed

I have changed my django debug to false. I am now missing the bootstrap files, previously found in the static directory. The console output shows i'm getting 404s on the bootstrap files.
debug output:
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[23/Sep/2022 12:49:42] "GET /login/?next=/ HTTP/1.1" 200 2853
[23/Sep/2022 12:49:42] "GET /static/css/bootstrap.min.css HTTP/1.1" 404 179
[23/Sep/2022 12:49:42] "GET /static/orchestration/main.css HTTP/1.1" 404 179
[23/Sep/2022 12:49:42] "GET /static/js/jquery.min.js HTTP/1.1" 404 179
[23/Sep/2022 12:49:42] "GET /static/js/popper.min.js HTTP/1.1" 404 179
[23/Sep/2022 12:49:42] "GET /static/js/bootstrap.min.js HTTP/1.1" 404 179
[23/Sep/2022 12:49:42] "GET /static/js/bootstrap.min.js HTTP/1.1" 404 179
settings.py
STATIC_URL = 'static/'
#----
STATIC_ROOT = os.path.join(BASE_DIR, 'root')
#----
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'boot'),
]
I have run python3 manage.py collectstatic. It has copied all these files to the root directory. I was expecting it just to look in the root directory to find them.

Django admin page. When i run the server everything will be fine, but when i try log into the admin page i will lose my connection

Am getting back the last line after i navigate to the 127.0.0.1:8000/admin
the browser message
This site can’t be reached127.0.0.1 refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
my terminal message
"C:\Program Files\JetBrains\PyCharm 2019.2\bin\runnerw64.exe" C:\Users\UCHE\PycharmProjects\blog\venv\Scripts\python.exe C:/Users/UCHE/PycharmProjects/blog/manage.py runserver 8000
Performing system checks...
Watching for file changes with StatReloader
System check identified no issues (0 silenced).
March 16, 2020 - 22:15:50
Django version 3.0.4, using settings 'blog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[16/Mar/2020 22:16:26] "GET / HTTP/1.1" 200 19
Not Found: /favicon.ico
[16/Mar/2020 22:16:28] "GET /favicon.ico HTTP/1.1" 404 2136
[16/Mar/2020 22:16:34] "GET /admin/ HTTP/1.1" 302 0
[16/Mar/2020 22:16:34] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[16/Mar/2020 22:16:35] "GET /static/admin/css/base.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:35] "GET /static/admin/css/login.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:35] "GET /static/admin/css/responsive.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:35] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:36] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[16/Mar/2020 22:16:36] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[16/Mar/2020 22:16:49] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
Process finished with exit code -1
Have you created a super user, ? If you haven't created a super user create one and login to admin of django project.
Use following comand to create a super user
python manage.py createsuperuser

How to resolve django admin error with 302 problems?

I am continuously getting error while trying to log in to django admin page.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 07, 2019 - 13:53:40
Django version 3.0, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /
[07/Dec/2019 13:53:42] "GET / HTTP/1.1" 404 2027
[07/Dec/2019 13:53:47] "GET /admin HTTP/1.1" 301 0
[07/Dec/2019 13:53:47] "GET /admin/ HTTP/1.1" 302 0
[07/Dec/2019 13:53:47] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[07/Dec/2019 13:53:47] "GET /static/admin/css/login.css HTTP/1.1" 200 1233
[07/Dec/2019 13:53:47] "GET /static/admin/css/base.css HTTP/1.1" 200 16378
[07/Dec/2019 13:53:47] "GET /static/admin/css/responsive.css HTTP/1.1" 200 18052
[07/Dec/2019 13:53:47] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[07/Dec/2019 13:53:47] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[07/Dec/2019 13:53:47] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[07/Dec/2019 13:53:59] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
And after this it is automatically closing.
I used python v3.7 and got this issue. Solved this problem by using python v3.8 and creating a new venv.
Now my python version FYI:
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
302 is not an error. It is a redirect. When you try to visit /admin/ you are redirected to the login page, and then when you have logged in you are redirected to /admin/.
I set SESSION_COOKIE_SECURE = False in settings.py and works.

When I try to login to Django admin via https, python server was closed without any error

I follow the Official Django tutorial, but I´m stucked in the point where I should login into Admin page. I can fill name and password, but after hit Log in button, python development server ends. I´m running them using this command python manage.py runserver 0.0.0.0:3000
I´m running Linux container on Codeanywhere using Python 3.7 and Django 3.1.
Only output I get is:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
October 04, 2019 - 16:14:47
Django version 3.1, using settings 'buky.settings'
Starting development server at http://0.0.0.0:3000/
Quit the server with CONTROL-C.
[04/Oct/2019 16:14:48] "GET /admin/ HTTP/1.1" 302 0
[04/Oct/2019 16:14:49] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1916
[04/Oct/2019 16:14:49] "GET /static/admin/css/base.css HTTP/1.1" 200 16378
[04/Oct/2019 16:14:49] "GET /static/admin/css/login.css HTTP/1.1" 200 1233
[04/Oct/2019 16:14:49] "GET /static/admin/css/responsive.css HTTP/1.1" 200 18052
[04/Oct/2019 16:14:49] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[04/Oct/2019 16:14:50] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[04/Oct/2019 16:14:50] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[04/Oct/2019 16:14:57] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
My urls.py is like in tutorial:
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
What can be wrong?
Thanks Alex
I updated my python version from 3.7.0 to 3.8.1 and the problem was fixed for me.
Hope it helps for you too! Cheers

More trailing slashes being added at every refresh - Django

I'm using django 1.3.1 and in my application and I have set DEBUG = False in my settings.py. when I refresh the page, the url is going into some loop process and in every loop a slash is being appended to the static files and due to this no static files are being called. I have pasted a sample terminal output below. What could be reason and how can I resolve this?
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg//////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg///////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg/////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg//////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg///////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg/////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg//////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:31] "GET /static/img/admin/logo.jpg///////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:31] "GET /static/img/admin/logo.jpg////////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:31] "GET /static/img/admin/logo.jpg/////////////////// HTTP/1.1" 301 0
This works fine when I set DEBUG = True in my settings.py.
After a little search, I found this question very helpful. Why does DEBUG=False setting make my django Static Files Access fail?
With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that.
If you still need to server static locally (e.g. for testing without debug) you can run devserver in insecure mode: manage.py runserver --insecure