Below is my vue front-end build(npm rum build on vue-cli 3).
And below is my run.py file for flask back-end.
from flask import Flask, render_template
class CustomFlask(Flask):
jinja_options = Flask.jinja_options.copy()
jinja_options.update(dict(
variable_start_string='%%',
variable_end_string='%%',
))
app = CustomFlask(__name__,
static_folder="./dist",
template_folder="./dist"
)
#app.route('/')
def index():
return render_template("index.html")
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
as you can see, I've changed default flask static, template directory to ./dist due to my dist structure. But when I try to test my app, I got below messages.
Chrome console
vendor.97db904d.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.9aaff056.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.197e53a9.css Failed to load resource: the server responded with a status of 404 (NOT FOUND)
vendor.97db904d.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.9aaff056.js Failed to load resource: the server responded with a status of 404 (NOT FOUND)
app.197e53a9.css Failed to load resource: the server responded with a status of 404 (NOT FOUND)
flask
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/vendor.97db904d.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/app.9aaff056.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /css/app.197e53a9.css HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/vendor.97db904d.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/manifest.ce28c628.js.map HTTP/1.1" 404 -
127.0.0.1 - - [11/Apr/2018 19:44:21] "GET /js/app.9aaff056.js HTTP/1.1" 404 -
How can I change properly static/template directory on flask? or should I change my build configuration on vue-cli3(webpack)? I have no more clue on this. Please give me a hint if you can. Thank you in advance.
If you change vue-cli build to put the content of the dist folder in the Flask static folder that would work.
However you'll need to change the way you initialize Flask app and serve index.html file.
# vue-flask.py
from flask import Flask
app = Flask(__name__, static_url_path='')
#app.route('/')
def index():
# changed to send_static_file
return app.send_static_file('index.html')
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
Here is the project structure:
I used the same approach in case of react and Flask integration but ended up splitting it down to two microservices as described here.
I've used this example in an app recently and it worked very well.
In particular the paragraph about configuring the redirects.
Related
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.
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
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
I little new to Apache HTTP 2.4 server and its module development. I have been playing around and created one sample mod_hello.so module to test. But facing the issue while deployment : -
Issue : - Not able to deploy the mod_hello.so file in Apache http 2.4 server
Steps performed : -
Copied the mod_hello.so file into the /usr/local/apache/modules/
directory
edited the httpd.conf file to load the module :- LoadModule
foo_module modules/mod_hello.so
Restarted the httpd service
But when i try to access using URL :localhost/foo i get 404
not found error on browser. In Actual it should produce 'Hello Word'
Message on browser.
In the logs i also checked but couldn't be able to find anything useful
Prior to above activity i have done the following
Build the Apache server 2.4 from source and intalled on fedora 15 system
For building used APR, APR-UTIL, PCRE
Everything went properly and able to compile the sample code and got the desired mod_hello.so file
Any help to debug this issue is highly appreciated
Logs
error_log
AH00558: httpd: Could not reliably determine the server's fully
qualified domain name, using localhost.localdomain. Set the
'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully
qualified domain name, using localhost.localdomain. Set the
'ServerName' directive globally to suppress this message
[Wed Nov 12 13:48:17.753498 2014] [core:warn] [pid 13514:tid
3077613776] AH00098: pid file /usr/local/apache/logs/httpd.pid
overwritten -- Unclean shutdown of previous Apache run?
access_log
::1 - - [12/Nov/2014:12:58:06 -0800] "GET / HTTP/1.1" 200 45
::1 - - [12/Nov/2014:12:58:06 -0800] "GET /favicon.ico HTTP/1.1" 404
209
::1 - - [12/Nov/2014:12:58:06 -0800] "GET /favicon.ico HTTP/1.1" 404
209
::1 - - [12/Nov/2014:13:48:24 -0800] "GET / HTTP/1.1" 200 45
::1 - - [12/Nov/2014:13:48:32 -0800] "GET /foo HTTP/1.1" 404 201
::1 - - [12/Nov/2014:13:48:34 -0800] "GET /foo HTTP/1.1" 404 201
Solution
I have created one fresh conf file in apache/conf/extra/mod_hello.conf and added following lines in it
LoadModule helloworld_module modules/libhello.so
<Location /helloworld>
SetHandler helloworld
</Location>
After the above change put added following line into httpd.conf file
Include conf/extra/mod_hello.conf
Restarted the server
./httpd -X
I am trying to develop a real time socket connection with django powered server built using gevent and greenlet. I started the server and the server is waiting on port 8000. But as soon as I load the page on the browser I see literally thousands of get requests (shown below) on the server terminal.
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648069-19838 HTTP/1.1" 200 172 0.004000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648074-19839 HTTP/1.1" 200 172 0.003000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648078-19840 HTTP/1.1" 200 172 0.003000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648083-19841 HTTP/1.1" 200 172 0.003000
127.0.0.1 - - [2014-06-21 13:10:48] "GET /socket.io/?EIO=2&transport=polling&t=1
403370648065-19837 HTTP/1.1" 200 172 0.004000
I am using version 1.0.6 of socket.io-client (https://github.com/Automattic/socket.io-client).
thanks,
I had this exact same problem, albeit with Express.IO on NodeJS and Socket.IO on the client side.
This issue will occur if the implementation versions of Socket.IO don't match between the client and server. For instance, there were a number of critical changes between Socket.IO v0.9 and v1.0. You need to either upgrade the one or downgrade the other.