Django redirecting to a different view in another appHow to combine 2 or more querysets in a Django view?Does Django scale?Question On Django Form ModelsDjango 1.8.3 urlsImage paths in Django view are relative to directory instead of MEDIA_URLurls.py django 2.0.2 need parameterspath('accounts/', include(accounts.urls)), NameError: name 'accounts' is not definedUnboundLocalError-local variable 'app' referenced before assignmentRedirect passing the entry id in the url - Django PythonDjango: Send JS dict to Django View

Output visual diagram of picture

Why do Radio Buttons not fill the entire outer circle?

Started in 1987 vs. Starting in 1987

Do I have to take mana from my deck or hand when tapping this card?

What is the meaning of "You've never met a graph you didn't like?"

What is this high flying aircraft over Pennsylvania?

Why didn't Voldemort know what Grindelwald looked like?

Did I make a mistake by ccing email to boss to others?

What should be the ideal length of sentences in a blog post for ease of reading?

What can I do if I am asked to learn different programming languages very frequently?

How to preserve electronics (computers, ipads, phones) for hundreds of years?

How do you say "Trust your struggle." in French?

How to split IPA spelling into syllables

Can you describe someone as luxurious? As in someone who likes luxurious things?

Index matching algorithm without hash-based data structures?

What is the tangent at a sharp point on a curve?

Asserting that Atheism and Theism are both faith based positions

Derivative of an interpolated function

Why does the Persian emissary display a string of crowned skulls?

Reason why a kingside attack is not justified

How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?

Are hand made posters acceptable in Academia?

Strange behavior in TikZ draw command

Why is "la Gestapo" feminine?



Django redirecting to a different view in another app


How to combine 2 or more querysets in a Django view?Does Django scale?Question On Django Form ModelsDjango 1.8.3 urlsImage paths in Django view are relative to directory instead of MEDIA_URLurls.py django 2.0.2 need parameterspath('accounts/', include(accounts.urls)), NameError: name 'accounts' is not definedUnboundLocalError-local variable 'app' referenced before assignmentRedirect passing the entry id in the url - Django PythonDjango: Send JS dict to Django View













0















There are many similar questions to mine on Stack Overflow, but none which solve my problem.



I have a class-based view which accepts files, and once a valid file is found, I would like the website to redirect the user to a template inside a different app, passing in some parameters.



I've seen others put an extra path in 'urlpatterns' and get the view from there. But doing this only makes a GET signal on my command prompt, but not actually changing the web url.



views.py



from django.shortcuts import render, redirect # used to render templates
from django.http import JsonResponse
from django.views import View

from .forms import UploadForm
from .models import FileUpload

class UploadView(View):
def get(self, request):
files_list = FileUpload.objects.all()
return render(self.request, 'upload/upload.html', 'csv_files': files_list)

def post(self, request):
form = UploadForm(self.request.POST, self.request.FILES)
if form.is_valid():
csv_file = form.save()
data = 'is_valid': True,
'name': csv_file.file.name,
'url': csv_file.file.url,
'date': csv_file.uploaded_at
# REDIRECT USER TO VIEW PASSING 'data' IN CONTEXT
return redirect('graph:chart', file_url=csv_file.file.url)
else:
data = 'is_valid': False
return JsonResponse(data)


urls.py



from django.urls import path
from . import views

app_name = "upload"

urlpatterns = [
path('', views.UploadView.as_view(), name='drag_and_drop'),
]


urls.py (of other app)



from django.urls import path
from . import views

app_name = "graph"

urlpatterns = [
path('', views.page, name='chart'),
]









share|improve this question




























    0















    There are many similar questions to mine on Stack Overflow, but none which solve my problem.



    I have a class-based view which accepts files, and once a valid file is found, I would like the website to redirect the user to a template inside a different app, passing in some parameters.



    I've seen others put an extra path in 'urlpatterns' and get the view from there. But doing this only makes a GET signal on my command prompt, but not actually changing the web url.



    views.py



    from django.shortcuts import render, redirect # used to render templates
    from django.http import JsonResponse
    from django.views import View

    from .forms import UploadForm
    from .models import FileUpload

    class UploadView(View):
    def get(self, request):
    files_list = FileUpload.objects.all()
    return render(self.request, 'upload/upload.html', 'csv_files': files_list)

    def post(self, request):
    form = UploadForm(self.request.POST, self.request.FILES)
    if form.is_valid():
    csv_file = form.save()
    data = 'is_valid': True,
    'name': csv_file.file.name,
    'url': csv_file.file.url,
    'date': csv_file.uploaded_at
    # REDIRECT USER TO VIEW PASSING 'data' IN CONTEXT
    return redirect('graph:chart', file_url=csv_file.file.url)
    else:
    data = 'is_valid': False
    return JsonResponse(data)


    urls.py



    from django.urls import path
    from . import views

    app_name = "upload"

    urlpatterns = [
    path('', views.UploadView.as_view(), name='drag_and_drop'),
    ]


    urls.py (of other app)



    from django.urls import path
    from . import views

    app_name = "graph"

    urlpatterns = [
    path('', views.page, name='chart'),
    ]









    share|improve this question


























      0












      0








      0








      There are many similar questions to mine on Stack Overflow, but none which solve my problem.



      I have a class-based view which accepts files, and once a valid file is found, I would like the website to redirect the user to a template inside a different app, passing in some parameters.



      I've seen others put an extra path in 'urlpatterns' and get the view from there. But doing this only makes a GET signal on my command prompt, but not actually changing the web url.



      views.py



      from django.shortcuts import render, redirect # used to render templates
      from django.http import JsonResponse
      from django.views import View

      from .forms import UploadForm
      from .models import FileUpload

      class UploadView(View):
      def get(self, request):
      files_list = FileUpload.objects.all()
      return render(self.request, 'upload/upload.html', 'csv_files': files_list)

      def post(self, request):
      form = UploadForm(self.request.POST, self.request.FILES)
      if form.is_valid():
      csv_file = form.save()
      data = 'is_valid': True,
      'name': csv_file.file.name,
      'url': csv_file.file.url,
      'date': csv_file.uploaded_at
      # REDIRECT USER TO VIEW PASSING 'data' IN CONTEXT
      return redirect('graph:chart', file_url=csv_file.file.url)
      else:
      data = 'is_valid': False
      return JsonResponse(data)


      urls.py



      from django.urls import path
      from . import views

      app_name = "upload"

      urlpatterns = [
      path('', views.UploadView.as_view(), name='drag_and_drop'),
      ]


      urls.py (of other app)



      from django.urls import path
      from . import views

      app_name = "graph"

      urlpatterns = [
      path('', views.page, name='chart'),
      ]









      share|improve this question
















      There are many similar questions to mine on Stack Overflow, but none which solve my problem.



      I have a class-based view which accepts files, and once a valid file is found, I would like the website to redirect the user to a template inside a different app, passing in some parameters.



      I've seen others put an extra path in 'urlpatterns' and get the view from there. But doing this only makes a GET signal on my command prompt, but not actually changing the web url.



      views.py



      from django.shortcuts import render, redirect # used to render templates
      from django.http import JsonResponse
      from django.views import View

      from .forms import UploadForm
      from .models import FileUpload

      class UploadView(View):
      def get(self, request):
      files_list = FileUpload.objects.all()
      return render(self.request, 'upload/upload.html', 'csv_files': files_list)

      def post(self, request):
      form = UploadForm(self.request.POST, self.request.FILES)
      if form.is_valid():
      csv_file = form.save()
      data = 'is_valid': True,
      'name': csv_file.file.name,
      'url': csv_file.file.url,
      'date': csv_file.uploaded_at
      # REDIRECT USER TO VIEW PASSING 'data' IN CONTEXT
      return redirect('graph:chart', file_url=csv_file.file.url)
      else:
      data = 'is_valid': False
      return JsonResponse(data)


      urls.py



      from django.urls import path
      from . import views

      app_name = "upload"

      urlpatterns = [
      path('', views.UploadView.as_view(), name='drag_and_drop'),
      ]


      urls.py (of other app)



      from django.urls import path
      from . import views

      app_name = "graph"

      urlpatterns = [
      path('', views.page, name='chart'),
      ]






      django






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 3:23







      Edwarric

















      asked Mar 7 at 1:30









      EdwarricEdwarric

      9317




      9317






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You can specify an app name and use exactly the redirect shortcut as you started:
          https://docs.djangoproject.com/en/2.1/topics/http/urls/#naming-url-patterns



          in the other app urls.py define app_name = 'other_app', and then use redirect(other_app:url_name', parameter1=p1, parameter2 = p2)



          you can name easily your parameters either using path (Django >=2.0) or url (re_path for Django >=2.0), for instance:




          from django.urls import path

          from . import views

          urlpatterns = [
          path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
          re_path(r'^articles/(?P<year>[0-9]4)/$', views.year_archive),
          ]





          share|improve this answer























          • I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

            – Edwarric
            Mar 7 at 3:26











          • your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

            – vctrd
            Mar 7 at 18:35










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034707%2fdjango-redirecting-to-a-different-view-in-another-app%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can specify an app name and use exactly the redirect shortcut as you started:
          https://docs.djangoproject.com/en/2.1/topics/http/urls/#naming-url-patterns



          in the other app urls.py define app_name = 'other_app', and then use redirect(other_app:url_name', parameter1=p1, parameter2 = p2)



          you can name easily your parameters either using path (Django >=2.0) or url (re_path for Django >=2.0), for instance:




          from django.urls import path

          from . import views

          urlpatterns = [
          path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
          re_path(r'^articles/(?P<year>[0-9]4)/$', views.year_archive),
          ]





          share|improve this answer























          • I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

            – Edwarric
            Mar 7 at 3:26











          • your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

            – vctrd
            Mar 7 at 18:35















          1














          You can specify an app name and use exactly the redirect shortcut as you started:
          https://docs.djangoproject.com/en/2.1/topics/http/urls/#naming-url-patterns



          in the other app urls.py define app_name = 'other_app', and then use redirect(other_app:url_name', parameter1=p1, parameter2 = p2)



          you can name easily your parameters either using path (Django >=2.0) or url (re_path for Django >=2.0), for instance:




          from django.urls import path

          from . import views

          urlpatterns = [
          path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
          re_path(r'^articles/(?P<year>[0-9]4)/$', views.year_archive),
          ]





          share|improve this answer























          • I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

            – Edwarric
            Mar 7 at 3:26











          • your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

            – vctrd
            Mar 7 at 18:35













          1












          1








          1







          You can specify an app name and use exactly the redirect shortcut as you started:
          https://docs.djangoproject.com/en/2.1/topics/http/urls/#naming-url-patterns



          in the other app urls.py define app_name = 'other_app', and then use redirect(other_app:url_name', parameter1=p1, parameter2 = p2)



          you can name easily your parameters either using path (Django >=2.0) or url (re_path for Django >=2.0), for instance:




          from django.urls import path

          from . import views

          urlpatterns = [
          path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
          re_path(r'^articles/(?P<year>[0-9]4)/$', views.year_archive),
          ]





          share|improve this answer













          You can specify an app name and use exactly the redirect shortcut as you started:
          https://docs.djangoproject.com/en/2.1/topics/http/urls/#naming-url-patterns



          in the other app urls.py define app_name = 'other_app', and then use redirect(other_app:url_name', parameter1=p1, parameter2 = p2)



          you can name easily your parameters either using path (Django >=2.0) or url (re_path for Django >=2.0), for instance:




          from django.urls import path

          from . import views

          urlpatterns = [
          path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail),
          re_path(r'^articles/(?P<year>[0-9]4)/$', views.year_archive),
          ]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 1:49









          vctrdvctrd

          18818




          18818












          • I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

            – Edwarric
            Mar 7 at 3:26











          • your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

            – vctrd
            Mar 7 at 18:35

















          • I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

            – Edwarric
            Mar 7 at 3:26











          • your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

            – vctrd
            Mar 7 at 18:35
















          I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

          – Edwarric
          Mar 7 at 3:26





          I have added app_name = "graph" and changed the redirect url in views.py (see question edit). I am confused about which urls.py I must edit and what view it must use?

          – Edwarric
          Mar 7 at 3:26













          your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

          – vctrd
          Mar 7 at 18:35





          your inputs are correct, what should be corrected is the way you pass the file reference to your other view. It seems you upload a file in the first view through a ModelForm. Then you should pass a reference to the object you saved in your database, rather than the url of the file (redirect can't be use to post data). In the other apps urls.py file edit: path('<int:file_id>', views.page, name='chart') and then: redirect('graph:chart', file_id=csv_file.id) edit your view function to retrieve the objects through its primary keyt: def page(request, file_id):

          – vctrd
          Mar 7 at 18:35



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034707%2fdjango-redirecting-to-a-different-view-in-another-app%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко