Skip to main content

Post/Redirect/Get-like approach for React + Django AJAX apps

Project description

logicore-django-react-pages

PRG-like approach for React + Django AJAX apps

Use together with: React counterpart

and on top of: Running React and Django on a single port

Usage

  1. Perform: https://github.com/Logicore-project/logicore-django-react#usage-from-scratch-starting-a-django--react-project-for-development

  2. Assuming your main apps' name is main

  3. Add to views.py (as an example):

from logicore_django_react_pages.views import ApiView

class HomeView(ApiView):
    url_name = "home"
    url_path = "/"
    WRAPPER = "MainWrapper"
    TEMPLATE = "HomeView"
    title = "Home"

    def get_data(self, request, *args, **kwargs):
        return {"name": "World"} 
  1. Add to urls.py
from logicore_django_react.urls import react_reload_and_static_urls, react_html_template_urls
from main import views # required to register subclasses for ApiView
from logicore_django_react_pages.views import all_api_urls

urlpatterns = [
    # ...
    *all_api_urls(), # in any position
    # ...
]

# add static/media endpoints here if needed
# urlpatterns += static(...)

# lastly, combine with logicore_django_react urls
urlpatterns = react_reload_and_static_urls + urlpatterns + react_html_template_urls
  1. Install & configure ReactJS counterpart: https://github.com/Logicore-project/logicore-react-pages#installation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logicore-django-react-pages-1.0.0.dev8.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page