Home > Blockchain >  Django - Not being able to merge front end to backend
Django - Not being able to merge front end to backend

Time:01-31

Im learning programming and im completely new in it..i was working on a project and i have used django for back-end. Now the problem im currenctly facing is that i got no idea how should i link frontend and backend ?.. first we created backend (where there is login/signup/and dashboard) using django and boostrap,js .. and the backend work perfectly so below the folder structure of the backend we are working on. enter image description here

so this is the structure of the backend .. to be more clear check 2nd image.

enter image description here

Here you can see that, budgetwebsite folder which is just below the folder authentication. budgetwebsite is our main thing or a part of our system..

then we did django startapp for authentication(for username validation and email)

then we did django startapp for userincome(here we worked on userincome like add/delete income)

then we did django startapp for expenses(here we worked on expenses like add/delete/expense)

and that userpreference is our admin panel.

thats for the backend section

Now lets move on the front end section aswell.

then we created a different folder name front end and we started working on it. enter image description here

So now lets move to the problem... i just want to merge this front end and back end ..

below is my code of setting.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'expenses',
    'userpreferences',
    'userincome',
]

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'main')],
            'APP_DIRS': True,
            'OPTIONS': {
                'context_processors': [
                    'django.template.context_processors.debug',
                    'django.template.context_processors.request',
                    'django.contrib.auth.context_processors.auth',
                    'django.contrib.messages.context_processors.messages',
                ],
            },
        },
    ]
    
    WSGI_APPLICATION = 'budgetwebsite.wsgi.application'
    
    STATIC_URL = '/static/'
    STATICFILES_DIRS=[os.path.join(BASE_DIR,'budgetwebsite/static')]
    STATIC_ROOT = os.path.join(BASE_DIR,'static')
    
    MESSAGE_TAGS ={
        messages.ERROR : "danger"
    }

urls.py

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('', include('expenses.urls')),
    path('authentication/', include('authentication.urls')),
    path('preferences/', include('userpreferences.urls')),
    path('income/', include('userincome.urls')),
    path('admin/', admin.site.urls),
]

enter image description here now my question is do i again have to startapp which i did for like expenses , income and authentication or is there any way i can easly merge my front end with backend. If you didn't understood the question im sorry .. and if the question is that appropriate then im sorry for that aswell. Thanks.

CodePudding user response:

Let's assume you want the user to get the expense app to open when he first visits your wesite

So the expense app will have it's own views.py and you have to create a urls.py for it and also all the other apps too.

now in the urls.py file of the expense you have to write the url patternss for that app

urls.py

from django.urls import path

from . import views

urlpatterns=[
    path('expense', views.expense, name= 'expense'),

]

similarly all the urls you want to display under the expense app has to written here first connected to a view function

views.py

from django.shortcuts import render

def expense(request):
   
    return render(request, 'expense.html') #or any other html file related to expese

all the pages related to the expense app will have different view function to render them and also url patterns connected to then so that the user can request

This is the most basic codes that you have to write to render any page related to the apps you want to display

  •  Tags:  
  • Related