Change url in Django












1















I am trying to load a pdf file in django which is already present in the database.
I can access the pdf file using the url, "localhost:8000/documents/file.pdf"
but when I perform the query and return the response containing this file, url it redirects to "localhost:8000/ans/documents/file.pdf" which doesn't exist.
The html code is:



<form id="signup-form" method="POST" action="ans/">
{% csrf_token %}
<input type="text" name="id" id="id" placeholder="Report id" />
<input type="submit" value="Check" />
</form>


The path in urls.py is



path('ans/',views.func),


The view is:



def func(request):
if request.method=="POST":
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})
else:
return redirect(response)


The bottomline is, I wan't to get rid of the "/ans/" in the url.










share|improve this question























  • Try removing the action attribute from the form and provide feedback.

    – MiniGunnR
    Nov 24 '18 at 19:28











  • @MiniGunnR If I do that, then how will I pass the request to the view?

    – Tahseen Rahman
    Nov 24 '18 at 19:37











  • Create a different view that would uniquely render this pdf, define it in urls.py with it's own path and then use HttpResponseRedirect('that_new_path')

    – dmitryro
    Nov 24 '18 at 19:42













  • I didn't understand what you are trying to do in your view. Do you want to display the file somewhere or let someone to download it?

    – Rarblack
    Nov 24 '18 at 20:23











  • @TahseenRahman There is a certain way to write the view that is showing your form, using if else, in Django. It is not like you used to do in PHP. I've seen that action attribute can be skipped in Django forms. Please read up on Forms in django docs.

    – MiniGunnR
    Nov 24 '18 at 20:33
















1















I am trying to load a pdf file in django which is already present in the database.
I can access the pdf file using the url, "localhost:8000/documents/file.pdf"
but when I perform the query and return the response containing this file, url it redirects to "localhost:8000/ans/documents/file.pdf" which doesn't exist.
The html code is:



<form id="signup-form" method="POST" action="ans/">
{% csrf_token %}
<input type="text" name="id" id="id" placeholder="Report id" />
<input type="submit" value="Check" />
</form>


The path in urls.py is



path('ans/',views.func),


The view is:



def func(request):
if request.method=="POST":
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})
else:
return redirect(response)


The bottomline is, I wan't to get rid of the "/ans/" in the url.










share|improve this question























  • Try removing the action attribute from the form and provide feedback.

    – MiniGunnR
    Nov 24 '18 at 19:28











  • @MiniGunnR If I do that, then how will I pass the request to the view?

    – Tahseen Rahman
    Nov 24 '18 at 19:37











  • Create a different view that would uniquely render this pdf, define it in urls.py with it's own path and then use HttpResponseRedirect('that_new_path')

    – dmitryro
    Nov 24 '18 at 19:42













  • I didn't understand what you are trying to do in your view. Do you want to display the file somewhere or let someone to download it?

    – Rarblack
    Nov 24 '18 at 20:23











  • @TahseenRahman There is a certain way to write the view that is showing your form, using if else, in Django. It is not like you used to do in PHP. I've seen that action attribute can be skipped in Django forms. Please read up on Forms in django docs.

    – MiniGunnR
    Nov 24 '18 at 20:33














1












1








1








I am trying to load a pdf file in django which is already present in the database.
I can access the pdf file using the url, "localhost:8000/documents/file.pdf"
but when I perform the query and return the response containing this file, url it redirects to "localhost:8000/ans/documents/file.pdf" which doesn't exist.
The html code is:



<form id="signup-form" method="POST" action="ans/">
{% csrf_token %}
<input type="text" name="id" id="id" placeholder="Report id" />
<input type="submit" value="Check" />
</form>


The path in urls.py is



path('ans/',views.func),


The view is:



def func(request):
if request.method=="POST":
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})
else:
return redirect(response)


The bottomline is, I wan't to get rid of the "/ans/" in the url.










share|improve this question














I am trying to load a pdf file in django which is already present in the database.
I can access the pdf file using the url, "localhost:8000/documents/file.pdf"
but when I perform the query and return the response containing this file, url it redirects to "localhost:8000/ans/documents/file.pdf" which doesn't exist.
The html code is:



<form id="signup-form" method="POST" action="ans/">
{% csrf_token %}
<input type="text" name="id" id="id" placeholder="Report id" />
<input type="submit" value="Check" />
</form>


The path in urls.py is



path('ans/',views.func),


The view is:



def func(request):
if request.method=="POST":
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})
else:
return redirect(response)


The bottomline is, I wan't to get rid of the "/ans/" in the url.







python django python-3.x django-2.1






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 19:20









Tahseen RahmanTahseen Rahman

15




15













  • Try removing the action attribute from the form and provide feedback.

    – MiniGunnR
    Nov 24 '18 at 19:28











  • @MiniGunnR If I do that, then how will I pass the request to the view?

    – Tahseen Rahman
    Nov 24 '18 at 19:37











  • Create a different view that would uniquely render this pdf, define it in urls.py with it's own path and then use HttpResponseRedirect('that_new_path')

    – dmitryro
    Nov 24 '18 at 19:42













  • I didn't understand what you are trying to do in your view. Do you want to display the file somewhere or let someone to download it?

    – Rarblack
    Nov 24 '18 at 20:23











  • @TahseenRahman There is a certain way to write the view that is showing your form, using if else, in Django. It is not like you used to do in PHP. I've seen that action attribute can be skipped in Django forms. Please read up on Forms in django docs.

    – MiniGunnR
    Nov 24 '18 at 20:33



















  • Try removing the action attribute from the form and provide feedback.

    – MiniGunnR
    Nov 24 '18 at 19:28











  • @MiniGunnR If I do that, then how will I pass the request to the view?

    – Tahseen Rahman
    Nov 24 '18 at 19:37











  • Create a different view that would uniquely render this pdf, define it in urls.py with it's own path and then use HttpResponseRedirect('that_new_path')

    – dmitryro
    Nov 24 '18 at 19:42













  • I didn't understand what you are trying to do in your view. Do you want to display the file somewhere or let someone to download it?

    – Rarblack
    Nov 24 '18 at 20:23











  • @TahseenRahman There is a certain way to write the view that is showing your form, using if else, in Django. It is not like you used to do in PHP. I've seen that action attribute can be skipped in Django forms. Please read up on Forms in django docs.

    – MiniGunnR
    Nov 24 '18 at 20:33

















Try removing the action attribute from the form and provide feedback.

– MiniGunnR
Nov 24 '18 at 19:28





Try removing the action attribute from the form and provide feedback.

– MiniGunnR
Nov 24 '18 at 19:28













@MiniGunnR If I do that, then how will I pass the request to the view?

– Tahseen Rahman
Nov 24 '18 at 19:37





@MiniGunnR If I do that, then how will I pass the request to the view?

– Tahseen Rahman
Nov 24 '18 at 19:37













Create a different view that would uniquely render this pdf, define it in urls.py with it's own path and then use HttpResponseRedirect('that_new_path')

– dmitryro
Nov 24 '18 at 19:42







Create a different view that would uniquely render this pdf, define it in urls.py with it's own path and then use HttpResponseRedirect('that_new_path')

– dmitryro
Nov 24 '18 at 19:42















I didn't understand what you are trying to do in your view. Do you want to display the file somewhere or let someone to download it?

– Rarblack
Nov 24 '18 at 20:23





I didn't understand what you are trying to do in your view. Do you want to display the file somewhere or let someone to download it?

– Rarblack
Nov 24 '18 at 20:23













@TahseenRahman There is a certain way to write the view that is showing your form, using if else, in Django. It is not like you used to do in PHP. I've seen that action attribute can be skipped in Django forms. Please read up on Forms in django docs.

– MiniGunnR
Nov 24 '18 at 20:33





@TahseenRahman There is a certain way to write the view that is showing your form, using if else, in Django. It is not like you used to do in PHP. I've seen that action attribute can be skipped in Django forms. Please read up on Forms in django docs.

– MiniGunnR
Nov 24 '18 at 20:33












2 Answers
2






active

oldest

votes


















0














When you put ans/ it adds this to the url and file location is added right after it. To solve the issue remove ans/ and give name.



path('',views.func, name='func'),


Moreover, you have logical mistakes in view and form. You should have used either normal form or ModelForm to get id to form the form.



def func(request):
if request.method=="POST":
id=request.POST.get("id") # do not get id from url in post method
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})# do not render index.html just use HttpResponseRedirect. rendering is used for forms.
else:
return redirect(response) # redirecting to the file directly is a bad pattern.


Instead of these bad design, you should have used FileField in your models.py class and after that you would be eligible to get the url with file.url call in any place without redirecting it and you could easily assign it to any button.



Note: To skip the action attribute you should use I have mentioned above form and render it in the view method.



Edit :
Lets say you want to view the file from a specific object(You just need to pass the pk of the object which can be done with url template tag)



<a href="{% url 'specific_request' pk=query.pk %}">Specific request</a>


urls.py



path('response/request/<int:pk>/', views.specific_request, name='specific_request')


view.py



def specific_request(request, pk):

query = get_object_or_404(Request,
pk=pk)

context = {
'query': query
}

return render(request,
'view-request-specific.html',
context=context)




Now it is time to view the uploaded file on click
template.py



<label for="id_file">Uploaded file:   </label>
<a id="id_file" href="{{ query.file.url}}"> {{ query.file.url}}</a>


file.url is the magic to retrieve the exact url of the file. so when it is clicked the file will be opened.






share|improve this answer


























  • class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

    – Tahseen Rahman
    Nov 25 '18 at 5:50













  • And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

    – Tahseen Rahman
    Nov 25 '18 at 6:07











  • I am getting the url I wanted but it is showing me an error of Suspicious File Operation

    – Tahseen Rahman
    Nov 25 '18 at 6:13











  • My other question is Can I use get method in the form?

    – Tahseen Rahman
    Nov 25 '18 at 6:24











  • Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

    – Rarblack
    Nov 25 '18 at 8:07



















0














Remove the action attribute from your form tag in your template file and change your index function to something close to the following.



def index(request):
if request.method == "POST":
form = Form(request.POST)
if form.is_valid():
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return redirect("index.html")
else:
#return render (request,"ans.html",{'ans':response})
return redirect(response)
else:
form = Form()
return render(request,"index.html",{'form':form})


I have not tested the above code, so please provide feedback of any errors that you are seeing.






share|improve this answer
























  • I am getting the error of Suspicious File Operation.

    – Tahseen Rahman
    Nov 25 '18 at 12:00











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%2f53461594%2fchange-url-in-django%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














When you put ans/ it adds this to the url and file location is added right after it. To solve the issue remove ans/ and give name.



path('',views.func, name='func'),


Moreover, you have logical mistakes in view and form. You should have used either normal form or ModelForm to get id to form the form.



def func(request):
if request.method=="POST":
id=request.POST.get("id") # do not get id from url in post method
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})# do not render index.html just use HttpResponseRedirect. rendering is used for forms.
else:
return redirect(response) # redirecting to the file directly is a bad pattern.


Instead of these bad design, you should have used FileField in your models.py class and after that you would be eligible to get the url with file.url call in any place without redirecting it and you could easily assign it to any button.



Note: To skip the action attribute you should use I have mentioned above form and render it in the view method.



Edit :
Lets say you want to view the file from a specific object(You just need to pass the pk of the object which can be done with url template tag)



<a href="{% url 'specific_request' pk=query.pk %}">Specific request</a>


urls.py



path('response/request/<int:pk>/', views.specific_request, name='specific_request')


view.py



def specific_request(request, pk):

query = get_object_or_404(Request,
pk=pk)

context = {
'query': query
}

return render(request,
'view-request-specific.html',
context=context)




Now it is time to view the uploaded file on click
template.py



<label for="id_file">Uploaded file:   </label>
<a id="id_file" href="{{ query.file.url}}"> {{ query.file.url}}</a>


file.url is the magic to retrieve the exact url of the file. so when it is clicked the file will be opened.






share|improve this answer


























  • class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

    – Tahseen Rahman
    Nov 25 '18 at 5:50













  • And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

    – Tahseen Rahman
    Nov 25 '18 at 6:07











  • I am getting the url I wanted but it is showing me an error of Suspicious File Operation

    – Tahseen Rahman
    Nov 25 '18 at 6:13











  • My other question is Can I use get method in the form?

    – Tahseen Rahman
    Nov 25 '18 at 6:24











  • Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

    – Rarblack
    Nov 25 '18 at 8:07
















0














When you put ans/ it adds this to the url and file location is added right after it. To solve the issue remove ans/ and give name.



path('',views.func, name='func'),


Moreover, you have logical mistakes in view and form. You should have used either normal form or ModelForm to get id to form the form.



def func(request):
if request.method=="POST":
id=request.POST.get("id") # do not get id from url in post method
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})# do not render index.html just use HttpResponseRedirect. rendering is used for forms.
else:
return redirect(response) # redirecting to the file directly is a bad pattern.


Instead of these bad design, you should have used FileField in your models.py class and after that you would be eligible to get the url with file.url call in any place without redirecting it and you could easily assign it to any button.



Note: To skip the action attribute you should use I have mentioned above form and render it in the view method.



Edit :
Lets say you want to view the file from a specific object(You just need to pass the pk of the object which can be done with url template tag)



<a href="{% url 'specific_request' pk=query.pk %}">Specific request</a>


urls.py



path('response/request/<int:pk>/', views.specific_request, name='specific_request')


view.py



def specific_request(request, pk):

query = get_object_or_404(Request,
pk=pk)

context = {
'query': query
}

return render(request,
'view-request-specific.html',
context=context)




Now it is time to view the uploaded file on click
template.py



<label for="id_file">Uploaded file:   </label>
<a id="id_file" href="{{ query.file.url}}"> {{ query.file.url}}</a>


file.url is the magic to retrieve the exact url of the file. so when it is clicked the file will be opened.






share|improve this answer


























  • class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

    – Tahseen Rahman
    Nov 25 '18 at 5:50













  • And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

    – Tahseen Rahman
    Nov 25 '18 at 6:07











  • I am getting the url I wanted but it is showing me an error of Suspicious File Operation

    – Tahseen Rahman
    Nov 25 '18 at 6:13











  • My other question is Can I use get method in the form?

    – Tahseen Rahman
    Nov 25 '18 at 6:24











  • Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

    – Rarblack
    Nov 25 '18 at 8:07














0












0








0







When you put ans/ it adds this to the url and file location is added right after it. To solve the issue remove ans/ and give name.



path('',views.func, name='func'),


Moreover, you have logical mistakes in view and form. You should have used either normal form or ModelForm to get id to form the form.



def func(request):
if request.method=="POST":
id=request.POST.get("id") # do not get id from url in post method
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})# do not render index.html just use HttpResponseRedirect. rendering is used for forms.
else:
return redirect(response) # redirecting to the file directly is a bad pattern.


Instead of these bad design, you should have used FileField in your models.py class and after that you would be eligible to get the url with file.url call in any place without redirecting it and you could easily assign it to any button.



Note: To skip the action attribute you should use I have mentioned above form and render it in the view method.



Edit :
Lets say you want to view the file from a specific object(You just need to pass the pk of the object which can be done with url template tag)



<a href="{% url 'specific_request' pk=query.pk %}">Specific request</a>


urls.py



path('response/request/<int:pk>/', views.specific_request, name='specific_request')


view.py



def specific_request(request, pk):

query = get_object_or_404(Request,
pk=pk)

context = {
'query': query
}

return render(request,
'view-request-specific.html',
context=context)




Now it is time to view the uploaded file on click
template.py



<label for="id_file">Uploaded file:   </label>
<a id="id_file" href="{{ query.file.url}}"> {{ query.file.url}}</a>


file.url is the magic to retrieve the exact url of the file. so when it is clicked the file will be opened.






share|improve this answer















When you put ans/ it adds this to the url and file location is added right after it. To solve the issue remove ans/ and give name.



path('',views.func, name='func'),


Moreover, you have logical mistakes in view and form. You should have used either normal form or ModelForm to get id to form the form.



def func(request):
if request.method=="POST":
id=request.POST.get("id") # do not get id from url in post method
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})# do not render index.html just use HttpResponseRedirect. rendering is used for forms.
else:
return redirect(response) # redirecting to the file directly is a bad pattern.


Instead of these bad design, you should have used FileField in your models.py class and after that you would be eligible to get the url with file.url call in any place without redirecting it and you could easily assign it to any button.



Note: To skip the action attribute you should use I have mentioned above form and render it in the view method.



Edit :
Lets say you want to view the file from a specific object(You just need to pass the pk of the object which can be done with url template tag)



<a href="{% url 'specific_request' pk=query.pk %}">Specific request</a>


urls.py



path('response/request/<int:pk>/', views.specific_request, name='specific_request')


view.py



def specific_request(request, pk):

query = get_object_or_404(Request,
pk=pk)

context = {
'query': query
}

return render(request,
'view-request-specific.html',
context=context)




Now it is time to view the uploaded file on click
template.py



<label for="id_file">Uploaded file:   </label>
<a id="id_file" href="{{ query.file.url}}"> {{ query.file.url}}</a>


file.url is the magic to retrieve the exact url of the file. so when it is clicked the file will be opened.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 25 '18 at 13:39

























answered Nov 24 '18 at 20:42









RarblackRarblack

2,7654925




2,7654925













  • class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

    – Tahseen Rahman
    Nov 25 '18 at 5:50













  • And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

    – Tahseen Rahman
    Nov 25 '18 at 6:07











  • I am getting the url I wanted but it is showing me an error of Suspicious File Operation

    – Tahseen Rahman
    Nov 25 '18 at 6:13











  • My other question is Can I use get method in the form?

    – Tahseen Rahman
    Nov 25 '18 at 6:24











  • Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

    – Rarblack
    Nov 25 '18 at 8:07



















  • class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

    – Tahseen Rahman
    Nov 25 '18 at 5:50













  • And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

    – Tahseen Rahman
    Nov 25 '18 at 6:07











  • I am getting the url I wanted but it is showing me an error of Suspicious File Operation

    – Tahseen Rahman
    Nov 25 '18 at 6:13











  • My other question is Can I use get method in the form?

    – Tahseen Rahman
    Nov 25 '18 at 6:24











  • Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

    – Rarblack
    Nov 25 '18 at 8:07

















class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

– Tahseen Rahman
Nov 25 '18 at 5:50







class query(models.Model): id=models.IntegerField(primary_key=True) repo=models.FileField(upload_to='documents/') This is my models.py file. I am directly uploading the file through admin panel and I want it that way.

– Tahseen Rahman
Nov 25 '18 at 5:50















And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

– Tahseen Rahman
Nov 25 '18 at 6:07





And I am using a custom HTML 5 template to do this. The complete code can be found in www.github.com/tahseen09/delhipatho I am a beginner and if you could help me, I will be thankful to you.

– Tahseen Rahman
Nov 25 '18 at 6:07













I am getting the url I wanted but it is showing me an error of Suspicious File Operation

– Tahseen Rahman
Nov 25 '18 at 6:13





I am getting the url I wanted but it is showing me an error of Suspicious File Operation

– Tahseen Rahman
Nov 25 '18 at 6:13













My other question is Can I use get method in the form?

– Tahseen Rahman
Nov 25 '18 at 6:24





My other question is Can I use get method in the form?

– Tahseen Rahman
Nov 25 '18 at 6:24













Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

– Rarblack
Nov 25 '18 at 8:07





Yes you can definitely use get method in the form but you will get parameters from url then they will be shown in the url

– Rarblack
Nov 25 '18 at 8:07













0














Remove the action attribute from your form tag in your template file and change your index function to something close to the following.



def index(request):
if request.method == "POST":
form = Form(request.POST)
if form.is_valid():
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return redirect("index.html")
else:
#return render (request,"ans.html",{'ans':response})
return redirect(response)
else:
form = Form()
return render(request,"index.html",{'form':form})


I have not tested the above code, so please provide feedback of any errors that you are seeing.






share|improve this answer
























  • I am getting the error of Suspicious File Operation.

    – Tahseen Rahman
    Nov 25 '18 at 12:00
















0














Remove the action attribute from your form tag in your template file and change your index function to something close to the following.



def index(request):
if request.method == "POST":
form = Form(request.POST)
if form.is_valid():
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return redirect("index.html")
else:
#return render (request,"ans.html",{'ans':response})
return redirect(response)
else:
form = Form()
return render(request,"index.html",{'form':form})


I have not tested the above code, so please provide feedback of any errors that you are seeing.






share|improve this answer
























  • I am getting the error of Suspicious File Operation.

    – Tahseen Rahman
    Nov 25 '18 at 12:00














0












0








0







Remove the action attribute from your form tag in your template file and change your index function to something close to the following.



def index(request):
if request.method == "POST":
form = Form(request.POST)
if form.is_valid():
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return redirect("index.html")
else:
#return render (request,"ans.html",{'ans':response})
return redirect(response)
else:
form = Form()
return render(request,"index.html",{'form':form})


I have not tested the above code, so please provide feedback of any errors that you are seeing.






share|improve this answer













Remove the action attribute from your form tag in your template file and change your index function to something close to the following.



def index(request):
if request.method == "POST":
form = Form(request.POST)
if form.is_valid():
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return redirect("index.html")
else:
#return render (request,"ans.html",{'ans':response})
return redirect(response)
else:
form = Form()
return render(request,"index.html",{'form':form})


I have not tested the above code, so please provide feedback of any errors that you are seeing.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 8:42









MiniGunnRMiniGunnR

2,30732339




2,30732339













  • I am getting the error of Suspicious File Operation.

    – Tahseen Rahman
    Nov 25 '18 at 12:00



















  • I am getting the error of Suspicious File Operation.

    – Tahseen Rahman
    Nov 25 '18 at 12:00

















I am getting the error of Suspicious File Operation.

– Tahseen Rahman
Nov 25 '18 at 12:00





I am getting the error of Suspicious File Operation.

– Tahseen Rahman
Nov 25 '18 at 12:00


















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%2f53461594%2fchange-url-in-django%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

Lallio

Unable to find Lightning Node

Futebolista