Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am new to Django, I have started learning just a week ago. I am taking the reference of Django Docs, but I can't understand how to give url to an app. So can anybody please tell me how to give url to an app with description?
for example:- If I want to make a login form and when I click on login button it goes to the home page.
Django is a web framework
A web framework carry out common works for you(the web developer)
One of the common works is resolving the http request
One of the resolving is direct the request pointing to a URL to a specific piece of code which handles this request and generate the response.
We sometime call the stuff carrying out the above mechanism a URL router of the web framework. The piece of code in Django is a function(which generate a http response), we call it the view.
So we say the framework's URL router map a URL to a view.
You tell the router what URL maps to what view by listing your url-view mappings in the solo urls.py in the root directory of your project
If you dislike the solo urls.py being too large, you can split this file into multiple files, and put them in individual Apps directory. Then by using include syntax you aggregate them into the solo urls.py
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have to develop an API to manage data between my Database in PostGreSQL and my website in Django.
I'm actually looking for the best way to manage and transfer this data, what I actually found on different topics / sites is the Django Rest Framework to develop a Rest API in Django, here I would use a JavaScript framework for the front like React, Angular or VueJS (any tips about which one to choose ? ).
I was wondering if there was other solutions that would be interesting ? I've been searching about FTP or things like this.
Thanks,
Lucas
Like you said you need to send and retrieve information like name, contact, login detail etc related to user and their subscriptions.
In this case you don't have to think about FTP. It isn't related here. FTP is something that you'll use to transfer files without django.
With django you will have to use DRF (django rest framework) or use GraphQL along.
There is a package well known to use GraphQl called graphene
For front end part you can use anything according to your requirement and skillset.
Hope this helps.
Cheers
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to build a web application using Django. Basically a CRM for specific business type. Lets say it's for Gyms for this explanation. I will have multiple customers. The customers will each get their own 3rd level domain name. Like golds.gym.com and 24hrfitness.gym.com. Each customer will have their own customers that will use the site as well. I want to allow overlapping usernames across sites, but unique to each site. I would also like to use the built in admin pages, but I will need to be sure that the admin pages are site specific.
My question is more or less, "Is this possible". But I think what I really want to know is "Is this possible using something built in or something someone else has out there for Django?"
I have looked at the sites framework documentation and that seems to be what I need, however I have not found any documentation on how to make the admin and the users site specific.
You can definitely do it with the sites framework, but it does take a significant amount of bootstrapping. This also goes under the assumption that you will use a different hostname for each site, as this is how the sites framework works.
When you use the sites framework, there is middleware available that automatically populates the ID of the site on the request object.
If you want the end users to be able to use the admin section and see ONLY the objects on their account, you will need to have an account foreign key for every model.
You could then do something like overriding get_queryset in your views to automatically exclude any objects not belonging to the account.
Of course, you would also need a custom user model so that you can link users to sites.
If you are using postgres you could consider checking out Django Tenant Schemas, which accomplishes multi-tenancy using native postgres schemas.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am using Django 1.9 to build a link shortener. I have created a simple HTML page where the user can enter the long URL. I have also coded the methods for shortening this URL. The data is getting stored in the database and I am able to display the shortened URL to the user.
I want to know what I have to do next. What happens when a user visits the shorter URL? Should I use redirects or something else? I am totally clueless about this topic.
Normally when you provide a url shortner, after calling the url, you have to redirect to main url by 301 Permanently moved.
def resolve_url(request,url):
origin_url=resolve(url) # read from redis or so.
return HttpResponseRedirect(origin_url)
EDIT:
add code using #danny-cullen hint
You could just navigate to the URL via HttpResponseRedirect
Write a middleware instead of writing same code in every view, such that, if the shortened url is in the model that you stored the you can redirect the shortened url to the long url using HttpResponseRedirect.
class RedirectMiddleware(object):
# Check if client IP is allowed
def process_request(self, request):
'''you can get the current url from request and just filter with the model and redirect to longurl with HttpResponseRedirect.'''
return HttpResponseRedirect(full_url)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm still in the process of learning the basics of Django. I have a lot of questions. But the biggest one at the moment is to understand how I reuse admin models, forms and templates to display it on the frontend instead by going on the backend admin control panel.
What I've done so far is to create a url in urls.py, created a view in views.py and added template path, created the template.
Everything works well with that. But how do I just "copy" the admin model that I want so the user that is logged in can edit on the frontend instead?
What do I need to look more into to understand this so I can implement the admin on the frontend?
Though the admin can be configured through a permission system it is nothing that should be exposed to your front end users - it only should be used by users you can fully trust (administrators).
To implement similar functionality on the frontend look into Django's ModelForms and Generic Views which should help you to implement simple CRUD actions rather quickly. If you would like to implement a Javascript based frontend something like Django-REST-Framework might be a good choice to implement something similar for a REST-API.
Nonetheless you could still add a second AdminSite to your project - but as stated above this is not really recommended for security reasons, if you would expose it to the "normal" user.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am building a simple Django app that will use scribd to display documents. I would like to have a page where the administrator can upload documents to scribd through the website, since I need to know a few things about it before it gets to scribd. What is the best/easiest way to do this, display an upload page and then take the file that is uploaded and send it to scribd through the docs.upload method of their api? I'm a little new at this Python/Django/REST API thing, so sorry if this is too many questions at once.
That is quite a few questions.
Handling the file upload is pretty straight-forward with Django, see the File Uploads documentation for examples. In short you can access the uploaded file via request.FILES['file'].
To call the scribd api you can use urllib2; see this Hackoarama page for instructions. urllib2 can be a little convoluted but it works once you get a hang of it.
You can call the scribd api directly from within your Django view, but it'd be better practice to separate it out: from within your Django view save the file somewhere on disk and put an "upload this" message on messaging system (eg. beanstalkd). Have a separate process pick up the message and upload the file to scribd. That way you shield your http process and user from any issues accessing the API and the associated delays.
What you want to do (at least from what I read here and on the Django documentation site) is create a custom storage system.
This should give you exactly what you need - it's the motivation they use to start the example, after all!