I created a Vue.js App with a Django Database. The Vue.js App is running with router and webpack-bundle. I want to deploy that App to Heroku, so I can access it from there. When I separately deploy them to Heroku it works, but not together in one combined app. My folder structure looks like that:
core/
├─ views.py
├─ __init__.py
frontend/
├─ node_modules/
├─ public/
│ ├─ favicon.ico
│ ├─ index.html
├─ src/
│ ├─ views/
│ ├─ App.vue
│ ├─ main.js
│ ├─ router.js
├─ .gitignore
├─ package.json
├─ README.md
├─ vue.config.js
├─ webpack-stats.json
my-app-products/
├─ api/
├─ admin.py
├─ apps.py
├─ models.py
├─ views.py
my-app-shop/
├─ asgi.py
├─ settings.py
├─ urls.py
├─ wsgi.py
├─ __init__.py
The main problem I encounter is, that the vue app is in a subdirectory and I don't know how to deploy two apps in Heroku. If that is even possible, to deploy two apps in one project.
I have knowledge on using git and on changing the heroku buildpack.
Thanks in advance
Related
I have one problem with pytest. I am creating objects and I like to test these objects if they are complete or buggy. Now the thing: When I put the test script into the src-folder, it works fine. But when I want to use it in a tests folder, I get always an error, that if I like to load my object, a module is not found.
in this structure it works:
my-app/
├─ output/
├─ input/
├─ src/
│ ├─ some_package/
│ ├─ some_code.py
│ ├─ test.py
This structure gives me a ModuleNotFoundError:
my-app/
├─ output/
├─ input/
├─ src/
│ ├─ some_package/
│ ├─ some_code.py
├─ test/
│ ├─ test.py (with changed the relative paths)
I guess that pytest has some problems with using the correct path.
I have multiple small projects that are somewhat related to eachother so i want them to be in single sphinx documentation.
Each handler.py module have different docstring but when i build documentation both modules reference handler.py from App1.
Each App is single project but containing similar file names:
/
├─ conf.py
├─ index.rst
├─ App1/
│ ├─ handler.py
│ ├─ errors.py
│ ├─ DOCS/
│ │ ├─ modules.rst
│ │ ├─ handler.rst
│ │ ├─ errors.rst
├─ App2/
│ ├─ DOCS/
│ │ ├─ modules.rst
│ │ ├─ handler.rst
│ ├─ handler.py
in root "conf.py" i insert paths for them:
sys.path.insert(0, os.path.abspath("App1/"))
sys.path.insert(0, os.path.abspath("App2/"))
in root "index.rst" i include them in toctree:
.. toctree::
:maxdepth: 12
:caption: Content:
app1/docs/modules
app2/docs/modules
each hander.rst contains:
handler module
================
.. automodule:: handler
:members:
:undoc-members:
:show-inheritance:
How should i structure or reference python files so that each App.handler page contains docstring only from that app handler.py?
i found this question in stackoverflow link.
but I still haven't received the answer to my question, what exactly is the standard project structure in Django?
my_project/
├─ my_project/
│ ├─ settings.py
│ ├─ wsgi.py
│ ├─ asgi.py
│ ├─ __init__.py
│ ├─ urls.py
├─ my_app/
│ ├─ __init__.py
│ ├─ urls.py
│ ├─ models.py
│ ├─ views.py
│ ├─ admin.py/
│ ├─ apps.py
│ ├─ tests.py
Does that answer your question?
If not, please write down what you do not understand
I have the following project structure:
my-app/
├─ README.md
├─ LICENSE
├─ tests/
│ ├─ my_test.py
├─ src/
│ ├─ utils/
│ │ ├─ __init__.py
│ │ ├─ utils.py
│ ├─ __init__.py
│ ├─ app.py
And my app.py (located in src) uses some functions of utils.py. When I run python src/app.py it works fine, but, when I run python -m unittest tests.my_tests for the tests code (which instantiates the main class at app.py) I get the following error:
from utils.utils import *
ModuleNotFoundError: No module named 'utils'
I'm new to coding so excuse me if this was a silly question but I couldn't find a clear answer anywhere.
So I have a django project with two apps inside it, both of them has the root '/',what is the exact format and implementation to use return redirect('/')to let django differentiate between these two roots in different apps maybe using naming routes.
a step by step guide will be appreciated, thank you in advance.
For example you have a django project called InitialProject and the project has 2 apps inside, let's call them MyApp1 and MyApp2.
Your directory structure should look something like this:
PythonProject/
├─ InitialProject/
│ ├─ __init__.py
│ ├─ asgi.py
│ ├─ settings.py
│ ├─ urls.py
│ ├─ wsgi.py
├─ MyApp1/
│ ├─ migrations/
│ ├─ filters.py
│ ├─ tests.py
│ ├─ urls.py
│ ├─ views.py
│ ├─ models.py
│ ├─ __init__.py
│ ├─ admin.py
│ ├─ apps.py
├─ MyApp2/
│ ├─ migrations/
│ ├─ filters.py
│ ├─ tests.py
│ ├─ urls.py
│ ├─ views.py
│ ├─ models.py
│ ├─ admin.py
│ ├─ __init__.py
│ ├─ apps.py
So firstly, URLs are unique, that is 1 URL can only lead to one path or one views function in this case. But what we can do is that we can say that URL starting with 'APP1' should look into MyApp1/urls.py for the function and URL starting with 'APP2' should look into MyApp2/urls.py
So in InitialProject/urls.py, we define it as follows:
from django.urls import path
from django.urls.conf import include
urlpatterns = [
path('APP1/', include('MyApp1.urls')), # Note the trailing forward slash, it is important
path('APP2/', include('MyApp2.urls')),
]
So, what this does is that is:
if your URL is: HTTP://localhost/APP1/
it will tell Django to look into MyApp1/urls.py to resolve and get the function and similarly for APP2.
Now in MyApp1/urls.py we can do is that:
from . import views
from django.urls import path
urlpatterns = [
path('', views.my_function_1), # This URL will resolve as HTTP://localhost/APP1/
path('second_url', views.my_function_2), # This URL will resolve as HTTP://localhost/APP1/second_url
]
And similarly can be done for MyApp2. By this method, you have a cleaner URL structure and it is also easy to navigate and see which app is being called.
I hope you are able to understand how URL Patterns work.
You might as why did we define the initial URL pattern in InitialProject/urls.py? Because by default Django will first go to the project directory to see which URL patterns and from there only we can link other App's URL patterns.